Spring framework 3.2 > 4.0 — themes and trends

Download Spring framework 3.2 > 4.0 — themes and trends

Post on 11-Jul-2015

4.046 views

Category:

Software

1 download

Embed Size (px)

TRANSCRIPT

  • Spring Framework 3.2 4.0

    Themes and Trends

  • / SK planet - Platform Software 1

    - (KSUG)

    - (La Scala Coding Dan)

    - (SpringSprout)

  • 2009.12.16 2012.12.132011.12.13

    3.0 3.1 3.2

  • Spring MVC 3.2 Update : 3 : Spring MVC : @ControllerAdvice : @MatrixVariable : : Interceptor : @RequestBody : RestTemplat / @RequestBody : Content negotiation :

    !

    Spring Core 3.2 Update : Java SE 7 / OpenJDK 7 : :

    !

    Next stop: Spring Framework 4.0

  • Spring MVC 3.2 Update

  • 3

    Spring MVC Update

    See Section 17.3.4, "Asynchronous Request Processing".

    @ReqeustMapping 3

  • ~ 2.5 : Thread per reqeust

    Spring MVC Update : 3

  • ~ 2.5 : Thread per reqeust

    Spring MVC Update : 3

  • ~ 2.5 : Thread per reqeust

    (1)

    Spring MVC Update : 3

  • 3.0 ~ :

    Spring MVC Update : 3

  • 3.0 ~ :

    Spring MVC Update : 3

  • 3.0 ~ :

    java.util.concurrent.Callable org.springframework.web.**.DeferredResult org.springframework.web.**.AsyncTask

    Spring MVC Update : 3

  • Callable

    @RequestMapping("/async/callable")public Callable callableWithView(final Model model) { return new Callable() { @Override public String call() throws Exception {! /* * : * - (xls, cvs, etc) * - (RESTful API, etc) * - * - etc */ return "view"; } };}

    Spring MVC Update : 3

  • Callable

    @RequestMapping("/async/callable")public Callable callableWithView(final Model model) { return new Callable() { @Override public String call() throws Exception {! /* * : * - (xls, cvs, etc) * - (RESTful API, etc) * - * - etc */ return "view"; } };}

    Spring MVC Update : 3

  • Callable

    @RequestMapping("/async/callable")public Callable callableWithView(final Model model) { return new Callable() { @Override public String call() throws Exception {! /* * : * - (xls, cvs, etc) * - (RESTful API, etc) * - * - etc */ return "view"; } };}

    Spring MVC Update : 3

  • DeferredResult final List reqeusts = new CopyOnWriteArrayList();!@RequestMapping(method= RequestMethod.GET)public @ResponseBody DeferredResult pullMessage() { final DeferredResult deferredResult = new DeferredResult(null, ""); reqeusts.add(deferredResult);! deferredResult.onCompletion(new Runnable() { public void run() { reqeusts.remove(deferredResult); } });! return deferredResult;}!@RequestMapping(method=RequestMethod.POST)public @ResponseBody void postMessage(@RequestParam String message) { for(DeferredResult deferredResult : reqeusts) { deferredResult.setResult(message); }}

    Spring MVC Update : 3

  • DeferredResult final List reqeusts = new CopyOnWriteArrayList();!@RequestMapping(method= RequestMethod.GET)public @ResponseBody DeferredResult pullMessage() { final DeferredResult deferredResult = new DeferredResult(null, ""); reqeusts.add(deferredResult);! deferredResult.onCompletion(new Runnable() { public void run() { reqeusts.remove(deferredResult); } });! return deferredResult;}!@RequestMapping(method=RequestMethod.POST)public @ResponseBody void postMessage(@RequestParam String message) { for(DeferredResult deferredResult : reqeusts) { deferredResult.setResult(message); }}

    Spring MVC Update : 3

  • DeferredResult final List reqeusts = new CopyOnWriteArrayList();!@RequestMapping(method= RequestMethod.GET)public @ResponseBody DeferredResult pullMessage() { final DeferredResult deferredResult = new DeferredResult(null, ""); reqeusts.add(deferredResult);! deferredResult.onCompletion(new Runnable() { public void run() { reqeusts.remove(deferredResult); } });! return deferredResult;}!@RequestMapping(method=RequestMethod.POST)public @ResponseBody void postMessage(@RequestParam String message) { for(DeferredResult deferredResult : reqeusts) { deferredResult.setResult(message); }}

    Spring MVC Update : 3

  • DeferredResult final List reqeusts = new CopyOnWriteArrayList();!@RequestMapping(method= RequestMethod.GET)public @ResponseBody DeferredResult pullMessage() { final DeferredResult deferredResult = new DeferredResult(null, ""); reqeusts.add(deferredResult);! deferredResult.onCompletion(new Runnable() { public void run() { reqeusts.remove(deferredResult); } });! return deferredResult;}!@RequestMapping(method=RequestMethod.POST)public @ResponseBody void postMessage(@RequestParam String message) { for(DeferredResult deferredResult : reqeusts) { deferredResult.setResult(message); }}

    Spring MVC Update : 3

  • DeferredResult final List reqeusts = new CopyOnWriteArrayList();!@RequestMapping(method= RequestMethod.GET)public @ResponseBody DeferredResult pullMessage() { final DeferredResult deferredResult = new DeferredResult(null, ""); reqeusts.add(deferredResult);! deferredResult.onCompletion(new Runnable() { public void run() { reqeusts.remove(deferredResult); } });! return deferredResult;}!@RequestMapping(method=RequestMethod.POST)public @ResponseBody void postMessage(@RequestParam String message) { for(DeferredResult deferredResult : reqeusts) { deferredResult.setResult(message); }}

    Spring MVC Update : 3

  • DeferredResult final List reqeusts = new CopyOnWriteArrayList();!@RequestMapping(method= RequestMethod.GET)public @ResponseBody DeferredResult pullMessage() { final DeferredResult deferredResult = new DeferredResult(null, ""); reqeusts.add(deferredResult);! deferredResult.onCompletion(new Runnable() { public void run() { reqeusts.remove(deferredResult); } });! return deferredResult;}!@RequestMapping(method=RequestMethod.POST)public @ResponseBody void postMessage(@RequestParam String message) { for(DeferredResult deferredResult : reqeusts) { deferredResult.setResult(message); }}

    Spring MVC Update : 3

  • 3 dispatcherServlet org.springframework.**.DispatcherServlet true dispatcherServlet /! encodingFilter org.springframework.**.CharacterEncodingFilter true encodingFilter /* REQUEST, ASYNC, FORWARD

    Spring MVC Update : 3

  • Spring MVC Test framework

    Spring MVC Update

    Spring MVC API DispatcherServlet RestTemplate

    See Section 11.3.6, "Spring MVC Test Framework".

  • MockMvc

    Spring MVC Update : Spring MVC Test framework

    MockMvc mockMvc = MockMvcBuilders.standaloneSetup( new HelloController() ).build();!mockMvc.perform( get("/hello").param("name", "arawn") ) .andExpect(status().isOk()) .andExpect(content().string(", arawn!"));

  • MockMvc

    Spring MVC Update : Spring MVC Test framework

    MockMvc mockMvc = MockMvcBuilders.standaloneSetup( new HelloController() ).build();!mockMvc.perform( get("/hello").param("name", "arawn") ) .andExpect(status().isOk()) .andExpect(content().string(", arawn!"));

  • MockMvc

    Spring MVC Update : Spring MVC Test framework

    MockMvc mockMvc = MockMvcBuilders.standaloneSetup( new HelloController() ).build();!mockMvc.perform( get("/hello").param("name", "arawn") ) .andExpect(status().isOk()) .andExpect(content().string(", arawn!"));

  • MockMvc

    Spring MVC Update : Spring MVC Test framework

    MockMvc mockMvc = MockMvcBuilders.standaloneSetup( new HelloController() ).build();!mockMvc.perform( get("/hello").param("name", "arawn") ) .andExpect(status().isOk()) .andExpect(content().string(", arawn!"));

  • : standaloneSetup

    Spring MVC Update : Spring MVC Test framework

    HelloController helloController = new HelloController();!MockMvc mockMvc = MockMvcBuilders .standaloneSetup(helloController) .addFilters(...) .addInterceptors(...) .setMessageConverters(...) .setViewResolvers(...) .build(); // Test CodemockMvc.perform(get("/hello").param("name", "arawn")) .andExpect(status().isOk()) .andExpect(content().string("Hello, arawn!"));

  • : standaloneSetup

    Spring MVC Update : Spring MVC Test framework

    HelloController helloController = new HelloController();!MockMvc mockMvc = MockMvcBuilders .standaloneSetup(helloController) .addFilters(...) .addInterceptors(...) .setMessageConverters(...) .setViewResolvers(...) .build(); // Test CodemockMvc.perform(get("/hello").param("name", "arawn")) .andExpect(status().isOk()) .andExpect(content().string("Hello, arawn!"));

  • : standaloneSetup

    Spring MVC Update : Spring MVC Test framework

    HelloController helloController = new HelloController();!MockMvc mockMvc = MockMvcBuilders .standaloneSetup(helloController) .addFilters(...) .addInterceptors(...) .setMessageConverters(...) .setViewResolvers(...) .build(); // Test CodemockMvc.perform(get("/hello").param("name", "arawn")) .andExpect(status().isOk()) .andExpect(content().string("Hello, arawn!"));

  • : standaloneSetup

    Spring MVC Update : Spring MVC Test framework

    HelloController helloController = new HelloController();!MockMvc mockMvc = MockMvcBuilders .standaloneSetup(helloController) .addFilters(...) .addInterceptors(...) .setMessageConverters(...) .setViewResolvers(...) .build(); // Test CodemockMvc.perform(get("/hello").param("name", "arawn")) .andExpect(status().isOk()) .andExpect(content().string("Hello, arawn!"));

  • : standaloneSetup

    Spring MVC Update : Spring MVC Test framework

    HelloController helloController = new HelloController();!MockMvc mockMvc = MockMvcBuilders .standaloneSetup(helloController) .addFilters(...) .addInterceptors(...) .setMessageConverters(...) .setViewResolvers(...) .build(); // Test CodemockMvc.perform(get("/hello").param("name", "arawn")) .andExpect(status().isOk()) .andExpect(content().string("Hello, arawn!"));

  • : webAppContextSetup

    Spring MVC Update : Spring MVC Test framework

    @RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes={ KSUGWebAppConfig.class })@WebAppConfigurationpublic class HelloControllerWebAppContextSetupTest {! @Autowired WebApplicationContext wac;! @Test public void testMVC() throws Exception {! MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac) .build();! // Test Code }!}

  • : webAppContextSetup

    Spring MVC Update : Spring MVC Test framework

    @RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes={ KSUGWebAppConfig.class })@WebAppConfigurationpublic class HelloControllerWebAppContextSetupTest {! @Autowired WebApplicationContext wac;! @Test public void testMVC() throws Exception {! MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac) .build();! // Test Code }!}

  • Spring MVC Update : Spring MVC Test framework

    @RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes={ KSUGWebAppConfig.class })@WebAppConfigurationpublic class HelloControllerWebAppContextSetupTest {! @Autowired WebApplicationContext wac;! @Test public void testMVC() throws Exception {! MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac) .build();! // Test Code }!}

    : webAppContextSetup

  • Spring MVC Update : Spring MVC Test framework

    @RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes={ KSUGWebAppConfig.class })@WebAppConfigurationpublic class HelloControllerWebAppContextSetupTest {! @Autowired WebApplicationContext ! @Test public void testMVC() throws Exception {! MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac) .build();! // Test Code }!}

    ServletContext !

    : webAppContextSetup

  • Spring MVC Update : Spring MVC Test framework

    @RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes={ KSUGWebAppConfig.class })@WebAppConfigurationpublic class HelloControllerWebAppContextSetupTest {! @Autowired WebApplicationContext wac;! MockMvc mockMvc;! @Test public void testMVC() throws Exception {! mockMvc = MockMvcBuilders.webAppContextSetup(wac) .build();! // Test Code }!}

    "src/main/webapp"

    : webAppContextSetup

  • Spring MVC Update : Spring MVC Test framework

    RestTemplate restTemplate = new RestTemplate();!MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);!mockServer.expect(requestTo("/hello")) .andRespond(withSuccess("Hello KSUG!", MediaType.TEXT_PLAIN));!String result = restTemplate.getForObject("/hello", String.class);!mockServer.verify();assertThat(result, is("Hello KSUG!"));

  • Spring MVC Update : Spring MVC Test framework

    RestTemplate restTemplate = new RestTemplate();!MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);!mockServer.expect(requestTo("/hello")) .andRespond(withSuccess("Hello KSUG!", MediaType.TEXT_PLAIN));!String result = restTemplate.getForObject("/hello", String.class);!mockServer.verify();assertThat(result, is("Hello KSUG!"));

  • Spring MVC Update : Spring MVC Test framework

    RestTemplate restTemplate = new RestTemplate();!MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);!mockServer.expect(requestTo("/hello")) .andRespond(withSuccess("Hello KSUG!", MediaType.TEXT_PLAIN));!String result = restTemplate.getForObject("/hello", String.class);!mockServer.verify();assertThat(result, is("Hello KSUG!"));

  • Spring MVC Update : Spring MVC Test framework

    RestTemplate restTemplate = new RestTemplate();!MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);!mockServer.expect(requestTo("/hello")) .andRespond(withSuccess("Hello KSUG!", MediaType.TEXT_PLAIN));!String result = restTemplate.getForObject("/hello", String.class);!mockServer.verify();assertThat(result, is("Hello KSUG!"));

  • @ControllerAdvice

    Spring MVC Update

    @ReqeustMapping @ExceptionHandler, @InitBinder, @ModelAttribute

    See Section 17, "Web MVC framework".

  • : @ControllerAdvice

    Spring MVC Update : @ControllerAdvice

    @Controllerpublic class ExampleController {! @InitBinder public void localInitBinder(WebDataBinder webDataBinder) { // webDataBinder.registerCustomEditor(requiredType, propertyEditor); }! @M...

Recommended

View more >