Tag: spring 4

找不到带URI的HTTP请求的映射(spring 4.1 annotation配置)

首先,请不要锁定这个post。 我已经阅读了所有问题,但仍然无法解决我的问题。 我正在研究如何在spring上使用注释而不配置xml文件。 我正在坚持这个错误: 在DispatcherServlet中找不到具有URI [/WEB-INF/index.jsp]的HTTP请求的映射,其名称为“dispatcherServlet” 这是项目结构 这是我的pom.xml 4.0.0 com.mycompany spring-sample 1.0 war spring-sample ${project.build.directory}/endorsed UTF-8 org.springframework.boot spring-boot-starter-parent 1.2.0.M2 javax javaee-web-api 7.0 provided org.springframework spring-context org.springframework.boot spring-boot-starter-web spring-milestones Spring Milestones http://repo.spring.io/milestone false spring-snapshots http://repo.spring.io/snapshot spring-milestones http://repo.spring.io/milestone org.apache.maven.plugins maven-compiler-plugin 3.1 1.7 1.7 ${endorsed.dir} org.apache.maven.plugins maven-war-plugin 2.3 false org.apache.maven.plugins maven-dependency-plugin 2.6 validate copy ${endorsed.dir} true javax javaee-endorsed-api […]

如何使用Spring 4.0.6全局设置FlushMode for Hibernate 4.3.5.Final?

我正在尝试使用Hibernate 4.3.5.Final和Spring 4.0.6升级我们的应用程序。 我的应用程序中数据库写入操作的任何位置都会出现如下错误: Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove ‘readOnly’ marker from transaction definition. at org.springframework.orm.hibernate4.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1135) at org.springframework.orm.hibernate4.HibernateTemplate$26.doInHibernate(HibernateTemplate.java:826) at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:340) at org.springframework.orm.hibernate4.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:308) at org.springframework.orm.hibernate4.HibernateTemplate.deleteAll(HibernateTemplate.java:823) … 以下是sessionFactory和transactionManager的spring配置: com/mycompany/Person.hbm.xml org.hibernate.dialect.HSQLDialect 1: 为了全局设置flushMode以便应用程序以与以前相同的方式工作,我需要将flushMode设置为全局,因此我不想使用@Transactional(readOnly = false)方法。 2: 在下面的post中,有人建议将singleSession设置为false, Java / Hibernate – 在只读模式下不允许写入操作 Spring文档建议指定“singleSession”=“false”有副作用: http […]

使用或不使用Spring Beans有什么区别?

可能我会得到很多downvotes,但是对于我来说,无论是否使用bean都是如此令人困惑。 让我们假设这个例子 interface ICurrency { String getSymbol(); } public class CurrencyProcessor { private ICurrency currency ; public CurrencyProcessor(ICurrency currency) { this.currency = currency; } public void doOperation(){ String symbol = currency.getSymbol(); System.out.println(“Doing process with ” + symbol + ” currency”); // Some process… } } 因此,为了注入ICurrency impl注入,我认为我可以通过两种方式实现: 方式1:没有春豆 public class CurrencyOperator { private ICurrency currency […]

Spring 4中有多个@ComponentScan?

我使用Spring 4.16和Java Annotations,我想做的事情如下: @Configuration @ComponentScan(basePackages = “com.example.business”, includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ServiceComponent.class)) @ComponentScan(basePackages = “com.example.business.framework”) public class ServicesBaseConfiguration { } 很可惜,它没有编译。 但我希望你明白我的观点。 我想要多个ComponentScans包含不同的包和filter。 我无法统一两个ComponentsScan,因为它不会从框架创建任何组件,而是那些用ServiceComponent注释的组件,我是对的吗? 你知道我怎么解决这个问题? 提前致谢

是否有Spring 4的Maven存储库?

我正在寻找Spring 4.0 M1,与Java 8一起使用。根据这个问题应该有一个构建,但是找不到。 理想情况下会有一个Maven回购,但我甚至找不到常规下载?

Spring4 MVCunit testing无法编译

在Spring 3.2.5→4.0.0版本更新后尝试编译源代码时,我有一些奇怪的行为。 ApplicationControllerTest.java错误代码片段(相当于文档中的代码): import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; … @Autowired private WebApplicationContext wac; private MockMvc mockMvc; @Before public void setUp() { mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); } 错误: COMPILATION ERROR : /C:/Development/…/war/src/test/java/org/…/web/controller/ApplicationControllerTest.java:[59,61] C:\Development\…\war\src\test\java\org\…\web\controller\ApplicationControllerTest.java:59: incompatible types; inferred type argument(s) java.lang.Object do not conform to bounds of type variable(s) B found : org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder required: java.lang.Object 如果看一下MockMvcBuilders来源,可以看出差异: […]

Spring 4中的websockets的动态消息映射

我想用spring新的websocket / stomp支持开发一个小聊天。 我想我不能用这样的东西: @MessageMapping(“/connect/{roomId}”) @SendTo(“/topic/newMessage”) public String connectToChatRoom(@PathVariable String roomId, Principal p) { return getTimestamp() + ” ” + p.getName() + ” connected to the room.”; } 这里有什么动态映射选项? 作为客户,我只想订阅我所在的房间。 提前致谢!

使用Spring 4 WebSocket从Java推送消息

我想将消息从Java推送到WebSocket客户端。 我已成功将js客户端发送到服务器并在2个js客户端上收到消息,因此客户端代码工作正常。 我的问题是,我想在Java应用程序中发生事件时发起发送。 因此,例如,每次放置10个订单时,向所有订阅的客户端发送消息。 这可能吗? 我当前的配置: @Controller public class MessageController { @MessageMapping(“/hello”) @SendTo(“/topic/greetings”) public Greeting greeting() throws Exception { return new Greeting(“Hello world”); } } 我希望能做的是这样的: public class OrderManager { @Autowired MessageController messageController; int orderCount = 0; public void processOrder(Order o) { orderCount++; if(orderCount % 10 == 0) messageController.greeting(); } } 所有订阅的websocket客户端都会收到一条消息。

像css / js这样的Spring 4静态内容会带来错误405请求方法’GET’不受支持

我已经检查了这个问题,但经过4个小时的尝试很多事情后,对我来说没什么用。 尝试访问我的css文件时出现405错误。 这是我的Config.java package com.myapp.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.view.JstlView; import org.springframework.web.servlet.view.UrlBasedViewResolver; @Configuration @ComponentScan(“com.myapp”) @EnableWebMvc @EnableTransactionManagement public class Config extends WebMvcConfigurerAdapter { @Bean public UrlBasedViewResolver setupViewResolver() { UrlBasedViewResolver resolver = new UrlBasedViewResolver(); resolver.setPrefix(“/WEB-INF/jsp/”); resolver.setSuffix(“.jsp”); resolver.setViewClass(JstlView.class); return resolver; } @Override public void addResourceHandlers(ResourceHandlerRegistry […]

Beancreationexception + NosuchBeandefinitionexception

我正在使用SpringBoot处理Spring 4应用程序。 在com.test.tm包中, 申请类: @SpringBootApplication @EnableJpaRepositories( repositoryFactoryBeanClass = GenericRepositoryFactoryBean.class ) @Import( { HikariDataSourceConfig.class } ) public class Application { public static void main( String[] args ) { SpringApplication.run(Application.class, args); } } 在com.test.tm.entities包中, 用户类: @Table( name = “test.user” ) @Entity public class User implements Serializable { @Id @GeneratedValue( strategy = GenerationType.AUTO ) private Integer id; private […]