Spring Framework Reference Documentation
Spring Framework Reference Documentation 読んだ
890ページあるpdfも提供してくれててこっち眺めてた(pdf直リン)
<exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion>
@Conditional
JDK 1.8’s java.util.Optional is now supported for @RequestParam
, @RequestHeader
, and @MatrixVariable
controller method arguments.
Test-managed transactions can now be programmatically started and ended within transactional test methods via the new TestTransaction
Test property sources which automatically override system and application property sources can be
configured via the new @TestPropertySource
<context:property-override location="classpath:override.properties"/>
MockRestServiceServer
: for RestTemplate and so on
@CookieValue
, @CacheEict
, @CrossOrigin
, @MatrixVariable
, @SessionAttributes
, @ActionMapping
, @RenderMapping
, @EventListener
, @TransactionalEventListener
improved ETag/Last-Modified support in WebRequest.
@DependsOn
: specify static processing dependencies
ここに書いてるbest practiceみたいの既に勝手にやってるな
EmbeddedDatabaseBuilder まじか
@EnableLoadTimeWeaving
ApplicationEventPublisherAware
→ ApplicationListener<PublishedEventClass>
or @EventListener
(with @Order
)
and more EntityCreatedEvent<T>
ValidationUtils
FormattingConversionService
← FormatterRegistrar
SpELは流し見
AOP、出来る限り使わんけど
@EnableAspectJAutoProxy
or <aop:aspectj-autoproxy/>
@AfterReturning
, @AfterThrowing
StopWatch
@EnableLoadTimeWeaving
or <context:load-time-weaver/>
TomcatLoadTimeWeaver
@Configuration @EnableLoadTimeWeaving public class AppConfig implements LoadTimeWeavingConfigurer { @Override public LoadTimeWeaver getLoadTimeWeaver() { return new ReflectiveLoadTimeWeaver(); } }
ModelAndViewAssert
JdbcTestUtils
@TestPropertySource
なるほど
Rollback semantics for integration tests in the Spring TestContext Framework default to true even if @Rollback is not explicitly declared
@IfProfileValue
, @Repeat(10)
, @TestExecutionListeners
@ContextHierarchy
<bean id="loginAction" class="com.example.LoginAction" c:username="{request.getParameter(''user'')}" c:password="{request.getParameter(''pswd'')}" scope="request"> <aop:scoped-proxy /> </bean>
これjava版だとどうやんだ
mockMvc.perform
からの.andDo(MockMvcResultHandlers.print())
でautodoc出来るんだな、簡単
MockMvcHtmlUnitDriverBuilder
@Transactional
default: ISOLATION_DEFAULT
WebApplicationInitializer
⇔ web.xml
HandlerExceptionResolver
@MatrixVariable
ほー
@JsonView
controllerからjava.util.concurrent.Callable
返すと非同期にリクエストの処理が走る
SpringMVCで返り値が決まらないやつ(etc. JMS)はDeferredResult
をcontrollerから返すと良い
<async-supported>true</async-supported>
in web.xml
Spring MVC 3.2 Preview: Introducing Servlet 3, Async Support
A controller method can use DeferredResult and Callable to produce its return value asynchronously and that can be used to implement techniques such as long polling where the server can push an event to the client as soon as possible.
HTTP StreamingしたいならResponseBodyEmitter
を使う
UriComponents uriComponents = MvcUriComponentsBuilder .fromMethodCall(on(BookingController.class).getBooking(21)).buildAndExpand(42); URI uri = uriComponents.encode().toUri();
MockMvc使う時これつこたらいいんか (MvcUriComponentsBuilder.on
)
Exception | HTTP Status Code |
---|---|
BindException 400 (Bad Request) | |
ConversionNotSupportedException | 500 (Internal Server Error) |
HttpMediaTypeNotAcceptableException | 406 (Not Acceptable) |
HttpMediaTypeNotSupportedException | 415 (Unsupported Media Type) |
HttpMessageNotReadableException | 400 (Bad Request) |
HttpMessageNotWritableException | 500 (Internal Server Error) |
HttpRequestMethodNotSupportedException | 405 (Method Not Allowed) |
MethodArgumentNotValidException | 400 (Bad Request) |
MissingServletRequestParameterException | 400 (Bad Request) |
MissingServletRequestPartException | 400 (Bad Request) |
NoHandlerFoundException | 404 (Not Found) |
NoSuchRequestHandlingMethodException | 404 (Not Found) |
TypeMismatchException | 400 (Bad Request) |
MissingPathVariableException | 500 (Internal Server Error) |
NoHandlerFoundException | 404 (Not Found) |
request.getAttribute("javax.servlet.error.status_code")
request.getAttribute("javax.servlet.error.message")
ShallowEtagHeaderFilter
@EnableWebMvc
⇔ `<mvc:annotation-driven/>
Jackson JSON and XML converters are created using ObjectMapper instances created by Jackson2ObjectMapperBuilder in order to provide a better default configuration. This builder customizes Jackson’s default properties with the following ones:
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
is disabled.MapperFeature.DEFAULT_VIEW_INCLUSION
is disabled.
FormattingConversionServiceFactoryBean
@Configuration @EnableWebMvc public class WebConfig extends WebMvcConfigurerAdapter { @Override public void addFormatters(FormatterRegistry registry) { // Add formatters and/or converters for Number, Date and so on } }
Content Nagotiation: The MVC Java config and the MVC namespace register json, xml, rss, atom by default
@Configuration @EnableWebMvc public class WebConfig extends WebMvcConfigurerAdapter { @Override public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { configurer.mediaType("json", MediaType.APPLICATION_JSON); } }
STOMP / WebSocket
WebSocketMessageBrokerStats
@CrossOrigin
@Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/api/**") .allowedOrigins("http://domain2.com") .allowedMethods("PUT", "DELETE") .allowedHeaders("header1", "header2", "header3") .exposedHeaders("header1", "header2") .allowCredentials(false).maxAge(3600); }
@WebService(serviceName="AccountService")
, @WebMethod
RestTemplate
, AsyncRestTemplate
(void返すかFuture返すか)
JMS: JmsTemplate
@Bean public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() { DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); factory.setConnectionFactory(connectionFactory()); factory.setDestinationResolver(destinationResolver()); factory.setConcurrency("3-10"); return factory; }
@Configuration @EnableJms public class AppConfig implements JmsListenerConfigurer { @Override public void configureJmsListeners(JmsListenerEndpointRegistrar registrar) { SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint(); endpoint.setId("myJmsEndpoint"); endpoint.setDestination("anotherQueue"); endpoint.setMessageListener(message -> { // processing }); registrar.registerEndpoint(endpoint); } }
org.springframework.jmx.export.MBeanExporter
@EnableMBeanExport
⇔ <context:mbean-export/>
server: org.springframework.jmx.support.ConnectorServerFactoryBean
client: org.springframework.jmx.support.MBeanServerConnectionFactoryBean
TaskExecutor
@EnableAsync
, @EnableScheduling
, @Scheduled
, @Async
動的コード生成をFrameworkが提供してる...
@Cacheable
, @CacheEvict
, @CachePut
, @Caching
, @CacheConfig