Tag: spring web

Prototype Bean无法按预期自动assembly

TestController.java @RestController public class TestController { @Autowired private TestClass testClass; @RequestMapping(value = “/test”, method = RequestMethod.GET) public void testThread(HttpServletResponse response) throws Exception { testClass.doSomething(); } } TestClass.java @Component @Scope(“prototype”) public class TestClass { public TestClass() { System.out.println(“new test class constructed.”); } public void doSomething() { } } 正如您所看到的,我正在尝试确定在访问“xxx / test”时是否注入了新的TestClass 。 “new test class constructed.” […]

Spring的@RequestParam与Enum

我有这个枚举: public enum SortEnum { asc, desc; } 我想用作rest请求的参数: @RequestMapping(value = “/events”, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public List getEvents(@RequestParam(name = “sort”, required = false) SortEnum sort) { 我发送这些请求时工作正常 /events /events?sort=asc /events?sort=desc 但是当我发送时: /events?sort=somethingElse 我在控制台中得到500响应和此消息: 2016-09-29 17:20:51.600 DEBUG 5104 — [ XNIO-2 task-6] com.myApp.aop.logging.LoggingAspect : Enter: com.myApp.web.rest.errors.ExceptionTranslator.processRuntimeException() with argument[s] = [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert […]

如何防止spring-web的弹簧自动配置?

我正在使用spring-boot并在maven pom中添加spring-web依赖,以使用RestTemplate 。 现在spring尝试初始化EmbeddedServletContext 。 我该怎样预防呢? Exception in thread “main” org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean. at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean. […]

Stomp spring web socket消息超出了大小限制

我正在我们的spring mvc web应用程序中实现spring web-socket。 但是当我尝试向端点发送一个非常大的消息时,我遇到了超过大小限制的消息。 我收到以下错误, message:The ‘content-length’ header 68718 exceeds the configured message buffer size limit 65536 14:49:11,506 ERROR [org.springframework.web.socket.messaging.StompSubProtocolHandler] (http-localhost/127.0.0.1:8080-4) Failed to parse TextMessage payload=[13684590},..], byteCount=16384, last=true] in session vlsxdeol. Sending STOMP ERROR to client.: org.springframework.messaging.simp.stomp.StompConversionException: The ‘content-length’ header 68718 exceeds the configured message buffer size limit 65536 at org.springframework.messaging.simp.stomp.BufferingStompDecoder.checkBufferLimits(BufferingStompDecoder.java:148) [spring-messaging-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.messaging.simp.stomp.BufferingStompDecoder.decode(BufferingStompDecoder.java:124) […]

Spring Rest Controller:如何有选择地关闭validation

在我的控制器中,我有一个创建实体的方法 import javax.validation.Valid; … @RestController public class Controller { @RequestMapping(method = RequestMethod.POST) public ResponseEntity create(@Valid @RequestBody RequestDTO requestDTO) { … 同 import org.hibernate.validator.constraints.NotEmpty; … public class RequestDTO @NotEmpty // (1) private String field1; //other fields, getters and setters. 我想添加一个控制器方法 update(@Valid @RequestBody RequestDTO requestDTO) 但是在这种方法中,应该允许field1为空或为空,即行 @NotEmpty // (1) RequestDTO应该被忽略。 我怎样才能做到这一点? 我是否必须编写一个与RequestDTO完全相同的类,但没有注释? 或者通过inheritance以某种方式可能?