Tag: spring

java.lang.NoSuchMethodError:org.hibernate.SessionFactory.openSession()Lorg / hibernate / classic / Session

我正在尝试将我已经工作的spring项目与hibernate集成,但这是我在启动时遇到的错误。 EVERE: Servlet.service() for servlet [appServlet] in context with path [/TelephoneDirectory] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;] with root cause java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session; at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:322) at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:233) at org.springframework.orm.hibernate3.HibernateTemplate.getSession(HibernateTemplate.java:457) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:393) at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912) at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904) at com.emumba.telephonedirectory.repository.JdbcPersonDao.getPersonsList(JdbcPersonDao.java:36) at com.emumba.telephonedirectory.service.SimpleDirectoryManager.getAllPersons(SimpleDirectoryManager.java:23) at com.emumba.telephonedirectory.web.HomeController.home(HomeController.java:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) […]

Spring Boot REST API – 请求超时?

我有一个Spring Boot REST服务,有时会将第三方服务作为请求的一部分。 我想在我的所有资源上设置一个超时(让我们说5秒),这样如果任何请求处理(整个链,从传入到响应)花费的时间超过5秒,我的控制器会响应HTTP 503而不是实际响应。 如果这只是一个Spring属性,例如设置,那将是非常棒的 spring.mvc.async.request-timeout=5000 但我没有运气。 我也尝试过扩展WebMvcConfigurationSupport并覆盖configureAsyncSupport: @Override public void configureAsyncSupport(final AsyncSupportConfigurer configurer) { configurer.setDefaultTimeout(5000); configurer.registerCallableInterceptors(timeoutInterceptor()); } @Bean public TimeoutCallableProcessingInterceptor timeoutInterceptor() { return new TimeoutCallableProcessingInterceptor(); } 没有运气。 我怀疑我必须手动计算所有第三方电话,如果他们花了太长时间,则抛出超时exception。 是对的吗? 或者是否有涵盖我所有请求端点的更简单,整体的解决方案?

Spring WebSocket @SendToSession:向特定会话发送消息

是否可以向特定会话发送消息? 我在客户端和Spring servlet之间有一个未经身份validation的websocket。 当异步作业结束时,我需要向特定连接发送未经请求的消息。 @Controller public class WebsocketTest { @Autowired public SimpMessageSendingOperations messagingTemplate; ExecutorService executor = Executors.newSingleThreadExecutor(); @MessageMapping(“/start”) public void start(SimpMessageHeaderAccessor accessor) throws Exception { String applicantId=accessor.getSessionId(); executor.submit(() -> { //… slow job jobEnd(applicantId); }); } public void jobEnd(String sessionId){ messagingTemplate.convertAndSend(“/queue/jobend”); //how to send only to that session? } } 正如您在此代码中看到的,客户端可以启动异步作业,当它完成时,它需要结束消息。 显然,我只需要向申请人发送信息,而不是向所有人广播。 拥有@SendToSession注释或messagingTemplate.convertAndSendToSession方法会很棒。 UPDATE 我试过这个: […]

使用Spring Boot和annotations配置ViewResolver为HTTP请求找不到URI错误的映射

我正在尝试使用gradle,spring boot和spring mvc以最简单的视图解析器和html制作“hello world”应用程序。 我从thymeleaf spring boot示例开始 ,我只是想删除thymeleaf,使用纯html和InternalResourceViewResolver创建一个更简单的mvc应用程序。 我有一个greeting.html我想要服务,它位于src / main / webapp / WEB-INF。 当我运行应用程序时,我得到了 No mapping found for HTTP request with URI [/WEB-INF/greeting.html] in DispatcherServlet with name ‘dispatcherServlet’ 这是一个常见的错误,网上有很多答案,但似乎没有任何帮助。 这是我的Application.java @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 这是我的GreetingController.java @Controller public class GreetingController { @RequestMapping(“/greeting”) public […]

如何在Spring MVC中找到所有控制器?

为了提供一些运行时生成的API文档,我想迭代所有Spring MVC控制器。 所有控制器都使用Spring @Controller注释进行注释。 目前我这样做: for (final Object bean: this.context.getBeansWithAnnotation( Controller.class).values()) { …Generate controller documentation for the bean… } 但是这段代码的第一次调用非常缓慢。 我想知道Spring是否迭代了类路径中的所有类,而不仅仅是检查定义的bean。 在运行上述代码时,控制器已经加载,日志显示所有这些控制器的请求映射,因此Spring MVC必须已经知道所有这些,并且必须有更快的方法来获取它们的列表。 但是怎么样?

如何使用spring MVC在JSP中包含js和CSS

我想在我的jsp中包含js和css文件,但我无法这样做。 我是Spring MVC概念的新手。 很长一段时间,我一直在研究同一个话题。 我的索引页面是这样的 body { background-image: url(“LoginPageBackgroundImage.jpg”); } Please login in google Chrome Welcome to my Twitter Clone Login User Name Password New User? Signup 我的spring-dispatcher-servlet.xml是这样的。 <!—-> <!– –> /WEB-INF/ .jsp 我的控制器是这样的。 package com.csc.student; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; @Controller public class StudentInfoController { @RequestMapping(value = “/indexPage.html”, method = RequestMethod.GET) […]

无法获得spring boot以自动创建数据库模式

当我启动它时,我无法让spring boot自动加载我的数据库模式。 这是我的application.properties: spring.datasource.url=jdbc:mysql://localhost:3306/test spring.datasource.username=test spring.datasource.password= spring.datasource.driverClassName = com.mysql.jdbc.Driver spring.jpa.database = MYSQL spring.jpa.show-sql = true spring.jpa.hibernate.ddl-auto = create spring.jpa.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect spring.jpa.hibernate.naming_strategy = org.hibernate.cfg.ImprovedNamingStrategy 这是我的Application.java: @EnableAutoConfiguration @ComponentScan public class Application { public static void main(final String[] args){ SpringApplication.run(Application.class, args); } } 这是一个示例实体: @Entity @Table(name = “survey”) public class Survey implements Serializable { private Long _id; […]

使用Spring Rest模板+ Spring Web MVC进行多部分文件上载

我试图使用RestTemplate上传一个文件与以下代码。 MultiValueMap multipartMap = new LinkedMultiValueMap(); multipartMap.add(“file”, new ClassPathResource(file)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(new MediaType(“multipart”, “form-data”)); HttpEntity<MultiValueMap> request = new HttpEntity<MultiValueMap>(multipartMap, headers); System.out.println(“Request for File Upload : ” + request); ResponseEntity result = template.get().exchange( contextPath.get() + path, HttpMethod.POST, request, byte[].class); 我有MultipartResolver bean和Controller代码 @RequestMapping(value = “/{id}/image”, method = RequestMethod.POST) @ResponseStatus(HttpStatus.NO_CONTENT) @Transactional(rollbackFor = Exception.class) public byte[] […]

在Spring AOP中使用代理

我正在读一本关于在Spring AOP中启用AspectJ支持的书。 以下是从该书中摘录的一段: 要在Spring IoC容器中启用AspectJ注释支持,您只需在bean配置文件中定义一个空的XML元素aop:aspectj-autoproxy。 然后,Spring将自动为您的AspectJ方面匹配的任何bean创建代理。 对于接口在应用程序设计中不可用或未使用的情况,可以依靠CGLIB创建代理。 要启用CGLIB,您需要在设置属性proxy-target-class=true 。 我无法得到第二段。 ‘ 接口不可用 ‘ 是什么意思。 任何人都可以用一个例子说明这一点

Spring限定符和属性占位符

有谁知道我是否应该使用属性占位符作为限定符中的表达式? 我似乎无法让这个工作。 我使用的是Spring 3.0.4。 @Controller public class MyController { @Autowired @Qualifier(“${service.class}”) Service service; } @Service @Qualifier(“ServiceA”) ServiceA implements Service { public void print() { System.out.println(“printing ServiceA.print()”); } } @Service @Qualifier(“ServiceB”) ServiceB implements Service { public void print() { System.out.println(“printing ServiceB.print()”); } } XML: config.properties: config.properties service.class=serviceB