From bbd5993945f91fdfcaecf86fc43e22e073753a36 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Fri, 26 Aug 2016 09:38:19 +0200 Subject: [PATCH] Consistently use annotation attributes in refdoc --- src/asciidoc/data-access.adoc | 8 +- src/asciidoc/integration.adoc | 6 +- src/asciidoc/testing.adoc | 82 +++++++++--------- src/asciidoc/web-cors.adoc | 14 ++-- src/asciidoc/web-mvc.adoc | 142 ++++++++++++++++---------------- src/asciidoc/web-view.adoc | 2 +- src/asciidoc/web-websocket.adoc | 2 +- 7 files changed, 128 insertions(+), 128 deletions(-) diff --git a/src/asciidoc/data-access.adoc b/src/asciidoc/data-access.adoc index a6d10969082..ef1faaee06d 100644 --- a/src/asciidoc/data-access.adoc +++ b/src/asciidoc/data-access.adoc @@ -1358,10 +1358,10 @@ example, using the qualifier notation, the following Java code ---- public class TransactionalService { - @Transactional("order") + @Transactional(transactionManager = "order") public void setSomething(String name) { ... } - @Transactional("account") + @Transactional(transactionManager = "account") public void doSomething() { ... } } ---- @@ -1403,13 +1403,13 @@ defining the following annotations ---- @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) - @Transactional("order") + @Transactional(transactionManager = "order") public @interface OrderTx { } @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) - @Transactional("account") + @Transactional(transactionManager = "account") public @interface AccountTx { } ---- diff --git a/src/asciidoc/integration.adoc b/src/asciidoc/integration.adoc index 977f0a5ba70..0634a43986b 100644 --- a/src/asciidoc/integration.adoc +++ b/src/asciidoc/integration.adoc @@ -8109,7 +8109,7 @@ of the cache associated with the annotated method: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @Cacheable("books") + @Cacheable(cacheNames = "books") public Book findBook(ISBN isbn) {...} ---- @@ -8130,7 +8130,7 @@ the cached method was not actually executed. [source,java,indent=0] [subs="verbatim,quotes"] ---- - @Cacheable({"books", "isbns"}) + @Cacheable(cacheNames = ""books", "isbns"}) public Book findBook(ISBN isbn) {...} ---- @@ -8177,7 +8177,7 @@ caching (while the rest are used only by the method logic). For example: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @Cacheable("books") + @Cacheable(cacheNames = "books") public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed) ---- diff --git a/src/asciidoc/testing.adoc b/src/asciidoc/testing.adoc index 4e975ef59af..79e5b59fe65 100644 --- a/src/asciidoc/testing.adoc +++ b/src/asciidoc/testing.adoc @@ -446,8 +446,8 @@ used within a test class hierarchy. [subs="verbatim,quotes"] ---- @ContextHierarchy({ - @ContextConfiguration("/parent-config.xml"), - @ContextConfiguration("/child-config.xml") + @ContextConfiguration(locations = "/parent-config.xml"), + @ContextConfiguration(locations = "/child-config.xml") }) public class ContextHierarchyTests { // class body... @@ -673,8 +673,8 @@ specified instead, as seen below. [subs="verbatim,quotes"] ---- @ContextHierarchy({ - @ContextConfiguration("/parent-config.xml"), - @ContextConfiguration("/child-config.xml") + @ContextConfiguration(locations = "/parent-config.xml"), + @ContextConfiguration(locations = "/child-config.xml") }) public class BaseTests { // class body... @@ -829,7 +829,7 @@ container annotation. @Test **@SqlGroup**({ @Sql(scripts = "/test-schema.sql", config = @SqlConfig(commentPrefix = "`")), - @Sql("/test-user-data.sql") + @Sql(scripts = "/test-user-data.sql") )} public void userTest { // execute code that uses the test schema and test data @@ -1009,14 +1009,14 @@ across our JUnit 4 based test suite... [subs="verbatim,quotes"] ---- @RunWith(SpringRunner.class) - @ContextConfiguration({"/app-config.xml", "/test-data-access-config.xml"}) - @ActiveProfiles("dev") + @ContextConfiguration(locations = ""/app-config.xml", "/test-data-access-config.xml"}) + @ActiveProfiles(profiles = "dev") @Transactional public class OrderRepositoryTests { } @RunWith(SpringRunner.class) - @ContextConfiguration({"/app-config.xml", "/test-data-access-config.xml"}) - @ActiveProfiles("dev") + @ContextConfiguration(locations = ""/app-config.xml", "/test-data-access-config.xml"}) + @ActiveProfiles(profiles = "dev") @Transactional public class UserRepositoryTests { } ---- @@ -1029,8 +1029,8 @@ that centralizes the common test configuration like this: ---- @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) - @ContextConfiguration({"/app-config.xml", "/test-data-access-config.xml"}) - @ActiveProfiles("dev") + @ContextConfiguration(locations = ""/app-config.xml", "/test-data-access-config.xml"}) + @ActiveProfiles(profiles = "dev") @Transactional public @interface TransactionalDevTest { } ---- @@ -1406,7 +1406,7 @@ demonstrated in the following example. [subs="verbatim,quotes"] ---- @RunWith(SpringRunner.class) - **@ContextConfiguration({"/app-config.xml", "/test-config.xml"})** + **@ContextConfiguration(locations = ""/app-config.xml", "/test-config.xml"})** public class MyTest { // class body... } @@ -1457,7 +1457,7 @@ TestContext Framework is enabled automatically if Groovy is on the classpath. @RunWith(SpringRunner.class) // ApplicationContext will be loaded from "/AppConfig.groovy" and // "/TestConfig.groovy" in the root of the classpath - **@ContextConfiguration({"/AppConfig.groovy", "/TestConfig.Groovy"})** + **@ContextConfiguration(locations = ""/AppConfig.groovy", "/TestConfig.Groovy"})** public class MyTest { // class body... } @@ -1500,7 +1500,7 @@ The following listing demonstrates how to combine both in an integration test. @RunWith(SpringRunner.class) // ApplicationContext will be loaded from // "/app-config.xml" and "/TestConfig.groovy" - @ContextConfiguration({ "/app-config.xml", "/TestConfig.groovy" }) + @ContextConfiguration(locations = " "/app-config.xml", "/TestConfig.groovy" }) public class MyTest { // class body... } @@ -1691,14 +1691,14 @@ therefore __override__ (i.e., replace) those defined in __"base-config.xml"__. @RunWith(SpringRunner.class) // ApplicationContext will be loaded from "/base-config.xml" // in the root of the classpath - **@ContextConfiguration("/base-config.xml")** + **@ContextConfiguration(locations = "/base-config.xml")** public class BaseTest { // class body... } // ApplicationContext will be loaded from "/base-config.xml" and // "/extended-config.xml" in the root of the classpath - **@ContextConfiguration("/extended-config.xml")** + **@ContextConfiguration(locations = "/extended-config.xml")** public class ExtendedTest extends BaseTest { // class body... } @@ -1822,8 +1822,8 @@ Let's take a look at some examples with XML configuration and `@Configuration` c @RunWith(SpringRunner.class) // ApplicationContext will be loaded from "classpath:/app-config.xml" - @ContextConfiguration("/app-config.xml") - @ActiveProfiles("dev") + @ContextConfiguration(locations = "/app-config.xml") + @ActiveProfiles(profiles = "dev") public class TransferServiceTest { @Autowired @@ -1843,7 +1843,7 @@ When `TransferServiceTest` is run, its `ApplicationContext` will be loaded from `dataSource` is defined three times: in the __production__ profile, the __dev__ profile, and the __default__ profile. -By annotating `TransferServiceTest` with `@ActiveProfiles("dev")` we instruct the Spring +By annotating `TransferServiceTest` with `@ActiveProfiles(profiles = "dev")` we instruct the Spring TestContext Framework to load the `ApplicationContext` with the active profiles set to `{"dev"}`. As a result, an embedded database will be created and populated with test data, and the `accountRepository` bean will be wired with a reference to the development @@ -1945,7 +1945,7 @@ integration test but using `@Configuration` classes instead of XML. StandaloneDataConfig.class, JndiDataConfig.class, DefaultDataConfig.class}) - @ActiveProfiles("dev") + @ActiveProfiles(profiles = "dev") public class TransferServiceTest { @Autowired @@ -1971,7 +1971,7 @@ In this variation, we have split the XML configuration into four independent no profile is active As with the XML-based configuration example, we still annotate `TransferServiceTest` -with `@ActiveProfiles("dev")`, but this time we specify all four configuration classes +with `@ActiveProfiles(profiles = "dev")`, but this time we specify all four configuration classes via the `@ContextConfiguration` annotation. The body of the test class itself remains completely unchanged. @@ -1993,7 +1993,7 @@ annotations) has been moved to an abstract superclass, `AbstractIntegrationTest` StandaloneDataConfig.class, JndiDataConfig.class, DefaultDataConfig.class}) - @ActiveProfiles("dev") + @ActiveProfiles(profiles = "dev") public abstract class AbstractIntegrationTest { } ---- @@ -2121,7 +2121,7 @@ be loaded using the specified resource protocol. Resource location wildcards (e. [subs="verbatim,quotes"] ---- @ContextConfiguration - @TestPropertySource("/test.properties") + @TestPropertySource(locations = "/test.properties") public class MyIntegrationTests { // class body... } @@ -2211,13 +2211,13 @@ only the `"base.properties"` file as a test property source. In contrast, the [source,java,indent=0] [subs="verbatim,quotes"] ---- - @TestPropertySource("base.properties") + @TestPropertySource(locations = "base.properties") @ContextConfiguration public class BaseTest { // ... } - @TestPropertySource("extended.properties") + @TestPropertySource(locations = "extended.properties") @ContextConfiguration public class ExtendedTest extends BaseTest { // ... @@ -2311,7 +2311,7 @@ nested `@Configuration` classes). @WebAppConfiguration("webapp") // classpath resource - @ContextConfiguration("/spring/test-servlet-config.xml") + @ContextConfiguration(locations = "/spring/test-servlet-config.xml") public class WacTests { //... @@ -2334,7 +2334,7 @@ whereas, `@ContextConfiguration` resource locations are classpath based. @WebAppConfiguration("classpath:test-web-resources") // file system resource - @ContextConfiguration("file:src/main/webapp/WEB-INF/servlet-config.xml") + @ContextConfiguration(locations = "file:src/main/webapp/WEB-INF/servlet-config.xml") public class WacTests { //... @@ -2554,13 +2554,13 @@ for the concrete subclasses. ---- @RunWith(SpringRunner.class) @WebAppConfiguration - @ContextConfiguration("file:src/main/webapp/WEB-INF/applicationContext.xml") + @ContextConfiguration(locations = "file:src/main/webapp/WEB-INF/applicationContext.xml") public abstract class AbstractWebTests {} - @ContextHierarchy(@ContextConfiguration("/spring/soap-ws-config.xml") + @ContextHierarchy(@ContextConfiguration(locations = "/spring/soap-ws-config.xml") public class SoapWebServiceTests extends AbstractWebTests {} - @ContextHierarchy(@ContextConfiguration("/spring/rest-ws-config.xml") + @ContextHierarchy(@ContextConfiguration(locations = "/spring/rest-ws-config.xml") public class RestWebServiceTests extends AbstractWebTests {} ---- -- @@ -2693,7 +2693,7 @@ The first code listing shows a JUnit 4 based implementation of the test class th ---- @RunWith(SpringRunner.class) // specifies the Spring configuration to load for this test fixture - **@ContextConfiguration("repository-config.xml")** + **@ContextConfiguration(locations= " repository-config.xml")** public class HibernateTitleRepositoryTests { // this instance will be dependency injected by type @@ -2716,7 +2716,7 @@ seen below. ---- @RunWith(SpringRunner.class) // specifies the Spring configuration to load for this test fixture - **@ContextConfiguration("repository-config.xml")** + **@ContextConfiguration(locations= " repository-config.xml")** public class HibernateTitleRepositoryTests { // this instance will be dependency injected by type @@ -3097,7 +3097,7 @@ to run within a transaction. `TransactionalTestExecutionListener` expects a `PlatformTransactionManager` bean to be defined in the Spring `ApplicationContext` for the test. In case there are multiple instances of `PlatformTransactionManager` within the test's `ApplicationContext`, a -_qualifier_ may be declared via `@Transactional("myTxMgr")` or +_qualifier_ may be declared via `@Transactional(transactionManager = "myTxMgr")` or `@Transactional(transactionManager = "myTxMgr")`, or `TransactionManagementConfigurer` can be implemented by an `@Configuration` class. Consult the javadocs for `TestContextTransactionUtils.retrieveTransactionManager()` for details on the algorithm @@ -3320,7 +3320,7 @@ level within a JUnit 4 based integration test class. ---- @RunWith(SpringRunner.class) @ContextConfiguration - @Sql("/test-schema.sql") + @Sql(scripts = "/test-schema.sql") public class DatabaseTests { @Test @@ -3329,7 +3329,7 @@ level within a JUnit 4 based integration test class. } @Test - @Sql({"/test-schema.sql", "/test-user-data.sql"}) + @Sql(scripts = ""/test-schema.sql", "/test-user-data.sql"}) public void userTest { // execute code that uses the test schema and test data } @@ -3366,7 +3366,7 @@ single-line comments. ---- @Test @Sql(scripts = "/test-schema.sql", config = @SqlConfig(commentPrefix = "`")) - @Sql("/test-user-data.sql") + @Sql(scripts = "/test-user-data.sql") public void userTest { // execute code that uses the test schema and test data } @@ -3381,7 +3381,7 @@ grouped together within `@SqlGroup` for compatibility with Java 6 and Java 7. @Test @SqlGroup({ @Sql(scripts = "/test-schema.sql", config = @SqlConfig(commentPrefix = "`")), - @Sql("/test-user-data.sql") + @Sql(scripts = "/test-user-data.sql") )} public void userTest { // execute code that uses the test schema and test data @@ -3482,7 +3482,7 @@ be automatically rolled back by the `TransactionalTestExecutionListener` (see } @Test - @Sql("/test-data.sql") + @Sql(scripts = "/test-data.sql") public void usersTest() { // verify state in test database: assertNumUsers(2); @@ -3719,7 +3719,7 @@ JUnit 4 based example of using Spring MVC Test: @RunWith(SpringRunner.class) @WebAppConfiguration - @ContextConfiguration("test-servlet-context.xml") + @ContextConfiguration(locations= " test-servlet-context.xml") public class ExampleTests { @Autowired @@ -3779,7 +3779,7 @@ into the test to use to build a `MockMvc` instance: ---- @RunWith(SpringRunner.class) @WebAppConfiguration - @ContextConfiguration("my-servlet-context.xml") + @ContextConfiguration(locations= " my-servlet-context.xml") public class MyWebTests { @Autowired @@ -3844,7 +3844,7 @@ expectations: ---- @RunWith(SpringRunner.class) @WebAppConfiguration - @ContextConfiguration("test-servlet-context.xml") + @ContextConfiguration(locations= " test-servlet-context.xml") public class AccountTests { @Autowired diff --git a/src/asciidoc/web-cors.adoc b/src/asciidoc/web-cors.adoc index d32a095f16b..1282f7e26aa 100644 --- a/src/asciidoc/web-cors.adoc +++ b/src/asciidoc/web-cors.adoc @@ -43,11 +43,11 @@ it. By default `@CrossOrigin` allows all origins and the HTTP methods specified [subs="verbatim,quotes"] ---- @RestController -@RequestMapping("/account") +@RequestMapping(path = "/account") public class AccountController { @CrossOrigin - @RequestMapping("/{id}") + @RequestMapping(path = "/{id}") public Account retrieve(@PathVariable Long id) { // ... } @@ -66,10 +66,10 @@ It is also possible to enable CORS for the whole controller: ---- @CrossOrigin(origins = "http://domain2.com", maxAge = 3600) @RestController -@RequestMapping("/account") +@RequestMapping(path = "/account") public class AccountController { - @RequestMapping("/{id}") + @RequestMapping(path = "/{id}") public Account retrieve(@PathVariable Long id) { // ... } @@ -93,11 +93,11 @@ then combine attributes from both annotations to create merged CORS configuratio ---- @CrossOrigin(maxAge = 3600) @RestController -@RequestMapping("/account") +@RequestMapping(path = "/account") public class AccountController { - @CrossOrigin("http://domain2.com") - @RequestMapping("/{id}") + @CrossOrigin(origins = "http://domain2.com") + @RequestMapping(path = "/{id}") public Account retrieve(@PathVariable Long id) { // ... } diff --git a/src/asciidoc/web-mvc.adoc b/src/asciidoc/web-mvc.adoc index 0663c768d7d..56bdd739e74 100644 --- a/src/asciidoc/web-mvc.adoc +++ b/src/asciidoc/web-mvc.adoc @@ -497,7 +497,7 @@ and others. @Controller public class HelloWorldController { - @RequestMapping("/helloWorld") + @RequestMapping(path = "/helloWorld") public String helloWorld(Model model) { model.addAttribute("message", "Hello World!"); return "helloWorld"; @@ -575,7 +575,7 @@ application that uses this annotation: [subs="verbatim,quotes"] ---- @Controller - **@RequestMapping("/appointments")** + **@RequestMapping(path = "/appointments")** public class AppointmentsController { private final AppointmentBook appointmentBook; @@ -639,11 +639,11 @@ application shows a multi-action controller using `@RequestMapping`: this.clinic = clinic; } - **@RequestMapping("/")** + **@RequestMapping(path = "/")** public void welcomeHandler() { } - **@RequestMapping("/vets")** + **@RequestMapping(path = "/vets")** public ModelMap vetsHandler() { return new ModelMap(this.clinic.getVets()); } @@ -676,7 +676,7 @@ previous section that has been simplified with _composed_ `@RequestMapping` anno [subs="verbatim,quotes"] ---- @Controller - **@RequestMapping("/appointments")** + **@RequestMapping(path = "/appointments")** public class AppointmentsController { private final AppointmentBook appointmentBook; @@ -691,12 +691,12 @@ previous section that has been simplified with _composed_ `@RequestMapping` anno return appointmentBook.getAppointmentsForToday(); } - **@GetMapping("/{day}")** + **@GetMapping(path = "/{day}")** public Map getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) { return appointmentBook.getAppointmentsForDay(day); } - **@GetMapping("/new")** + **@GetMapping(path = "/new")** public AppointmentForm getNewForm() { return new AppointmentForm(); } @@ -785,7 +785,7 @@ to the value of a URI template variable: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @GetMapping("/owners/{ownerId}") + @GetMapping(path = "/owners/{ownerId}") public String findOwner(**@PathVariable** String ownerId, Model model) { Owner owner = ownerService.findOwner(ownerId); model.addAttribute("owner", owner); @@ -807,7 +807,7 @@ template variable by name. You can specify it in the annotation: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @GetMapping("/owners/{ownerId}") + @GetMapping(path = "/owners/{ownerId}") public String findOwner(**@PathVariable("ownerId")** String theOwner, Model model) { // implementation omitted } @@ -821,7 +821,7 @@ template variable name: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @GetMapping("/owners/{ownerId}") + @GetMapping(path = "/owners/{ownerId}") public String findOwner(**@PathVariable** String ownerId, Model model) { // implementation omitted } @@ -833,7 +833,7 @@ A method can have any number of `@PathVariable` annotations: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @GetMapping("/owners/{ownerId}/pets/{petId}") + @GetMapping(path = "/owners/{ownerId}/pets/{petId}") public String findPet(**@PathVariable** String ownerId, **@PathVariable** String petId, Model model) { Owner owner = ownerService.findOwner(ownerId); Pet pet = owner.getPet(petId); @@ -882,7 +882,7 @@ name and the second - the regular expression. For example: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping("/spring-web/{symbolicName:[a-z-]+}-{version:\\d\\.\\d\\.\\d}{extension:\\.[a-z]+}") + @RequestMapping(path = "/spring-web/{symbolicName:[a-z-]+}-{version:\\d\\.\\d\\.\\d}{extension:\\.[a-z]+}") public void handle(@PathVariable String version, @PathVariable String extension) { // ... } @@ -1031,7 +1031,7 @@ Below is an example of extracting the matrix variable "q": ---- // GET /pets/42;q=11;r=22 - @GetMapping("/pets/{petId}") + @GetMapping(path = "/pets/{petId}") public void findPet(@PathVariable String petId, @MatrixVariable int q) { // petId == 42 @@ -1048,7 +1048,7 @@ specific to identify where the variable is expected to be: ---- // GET /owners/42;q=11/pets/21;q=22 - @GetMapping("/owners/{ownerId}/pets/{petId}") + @GetMapping(path = "/owners/{ownerId}/pets/{petId}") public void findPet( @MatrixVariable(name="q", pathVar="ownerId") int q1, @MatrixVariable(name="q", pathVar="petId") int q2) { @@ -1066,7 +1066,7 @@ A matrix variable may be defined as optional and a default value specified: ---- // GET /pets/42 - @GetMapping("/pets/{petId}") + @GetMapping(path = "/pets/{petId}") public void findPet(@MatrixVariable(required=false, defaultValue="1") int q) { // q == 1 @@ -1081,7 +1081,7 @@ All matrix variables may be obtained in a Map: ---- // GET /owners/42;q=11;r=12/pets/21;q=22;s=23 - @GetMapping("/owners/{ownerId}/pets/{petId}") + @GetMapping(path = "/owners/{ownerId}/pets/{petId}") public void findPet( @MatrixVariable MultiValueMap matrixVars, @MatrixVariable(pathVar="petId"") MultiValueMap petMatrixVars) { @@ -1208,7 +1208,7 @@ example with a request parameter value condition: [subs="verbatim,quotes"] ---- @Controller - @RequestMapping("/owners/{ownerId}") + @RequestMapping(path = "/owners/{ownerId}") public class RelativePathUriTemplateController { @GetMapping(path = "/pets/{petId}", **params = "myParam=myValue"**) @@ -1226,7 +1226,7 @@ specific request header value: [subs="verbatim,quotes"] ---- @Controller - @RequestMapping("/owners/{ownerId}") + @RequestMapping(path = "/owners/{ownerId}") public class RelativePathUriTemplateController { @GetMapping(path = "/pets", **headers = "myHeader=myValue"**) @@ -1380,7 +1380,7 @@ sample won't work: [subs="verbatim,quotes"] ---- @PostMapping - public String processSubmit(**@ModelAttribute("pet") Pet pet**, Model model, **BindingResult result**) { ... } + public String processSubmit(**@ModelAttribute(name = "pet") Pet pet**, Model model, **BindingResult result**) { ... } ---- Note, that there is a `Model` parameter in between `Pet` and `BindingResult`. To get @@ -1390,7 +1390,7 @@ this working you have to reorder the parameters as follows: [subs="verbatim,quotes"] ---- @PostMapping - public String processSubmit(**@ModelAttribute("pet") Pet pet**, **BindingResult result**, Model model) { ... } + public String processSubmit(**@ModelAttribute(name = "pet") Pet pet**, **BindingResult result**, Model model) { ... } ---- [NOTE] @@ -1463,14 +1463,14 @@ The following code snippet shows the usage: [subs="verbatim,quotes"] ---- @Controller - @RequestMapping("/pets") - @SessionAttributes("pet") + @RequestMapping(path = "/pets") + @SessionAttributes(names = "pet") public class EditPetForm { // ... @GetMapping - public String setupForm(**@RequestParam("petId") int petId**, ModelMap model) { + public String setupForm(**@RequestParam(name = "petId") int petId**, ModelMap model) { Pet pet = this.clinic.loadPet(petId); model.addAttribute("pet", pet); return "petForm"; @@ -1501,7 +1501,7 @@ be bound to the value of the HTTP request body. For example: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @PutMapping("/something") + @PutMapping(path = "/something") public void handle(@RequestBody String body, Writer writer) throws IOException { writer.write(body); } @@ -1580,7 +1580,7 @@ response body (and not placed in a Model, or interpreted as a view name). For ex [source,java,indent=0] [subs="verbatim,quotes"] ---- - @GetMapping("/something") + @GetMapping(path = "/something") @ResponseBody public String helloWorld() { return "Hello World"; @@ -1622,7 +1622,7 @@ so: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping("/something") + @RequestMapping(path = "/something") public ResponseEntity handle(HttpEntity requestEntity) throws UnsupportedEncodingException { String requestHeader = requestEntity.getHeaders().getFirst("MyRequestHeader"); byte[] requestBody = requestEntity.getBody(); @@ -1662,7 +1662,7 @@ couple of examples: ---- // Add one attribute // The return value of the method is added to the model under the name "account" - // You can customize the name via @ModelAttribute("myAccount") + // You can customize the name via @ModelAttribute(name = "myAccount") @ModelAttribute public Account addAccount(@RequestParam String number) { @@ -1728,7 +1728,7 @@ form field individually. [source,java,indent=0] [subs="verbatim,quotes"] ---- - @PostMapping("/owners/{ownerId}/pets/{petId}/edit") + @PostMapping(path = "/owners/{ownerId}/pets/{petId}/edit") public String processSubmit(**@ModelAttribute Pet pet**) { } ---- @@ -1750,8 +1750,8 @@ using an URI template variable and a type converter. Here is an example: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @PutMapping("/accounts/{account}") - public String save(@ModelAttribute("account") Account account) { + @PutMapping(path = "/accounts/{account}") + public String save(@ModelAttribute(name = "account") Account account) { // ... } ---- @@ -1775,8 +1775,8 @@ following the `@ModelAttribute` argument: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @PostMapping("/owners/{ownerId}/pets/{petId}/edit") - public String processSubmit(**@ModelAttribute("pet") Pet pet**, BindingResult result) { + @PostMapping(path = "/owners/{ownerId}/pets/{petId}/edit") + public String processSubmit(**@ModelAttribute(name = "pet") Pet pet**, BindingResult result) { if (result.hasErrors()) { return "petForm"; @@ -1808,7 +1808,7 @@ public Account findAccount(@PathVariable String accountId) { return accountRepository.findOne(accountId); } -@PostMapping("update") +@PostMapping(path = "update") public String update(@Valid AccountUpdateForm form, BindingResult result, **@ModelAttribute(binding=false)** Account account) { @@ -1824,8 +1824,8 @@ subsequently reported back to the user: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @PostMapping("/owners/{ownerId}/pets/{petId}/edit") - public String processSubmit(**@ModelAttribute("pet") Pet pet**, BindingResult result) { + @PostMapping(path = "/owners/{ownerId}/pets/{petId}/edit") + public String processSubmit(**@ModelAttribute(name = "pet") Pet pet**, BindingResult result) { new PetValidator().validate(pet, result); if (result.hasErrors()) { @@ -1843,8 +1843,8 @@ annotation: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @PostMapping("/owners/{ownerId}/pets/{petId}/edit") - public String processSubmit(**@Valid @ModelAttribute("pet") Pet pet**, BindingResult result) { + @PostMapping(path = "/owners/{ownerId}/pets/{petId}/edit") + public String processSubmit(**@Valid @ModelAttribute(name = "pet") Pet pet**, BindingResult result) { if (result.hasErrors()) { return "petForm"; @@ -1875,8 +1875,8 @@ attribute name: [subs="verbatim,quotes"] ---- @Controller - @RequestMapping("/editPet.do") - **@SessionAttributes("pet")** + @RequestMapping(path = "/editPet.do") + **@SessionAttributes(names = "pet")** public class EditPetForm { // ... } @@ -1893,7 +1893,7 @@ use the `@SessionAttribute` annotation on a method parameter: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping("/") + @RequestMapping(path = "/") public String handle(**@SessionAttribute** User user) { // ... } @@ -1917,7 +1917,7 @@ access pre-existing request attributes created by a filter or interceptor: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping("/") + @RequestMapping(path = "/") public String handle(**@RequestAttribute** Client client) { // ... } @@ -1991,8 +1991,8 @@ The following code sample demonstrates how to get the value of the `JSESSIONID` [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping("/displayHeaderInfo.do") - public void displayHeaderInfo(**@CookieValue("JSESSIONID")** String cookie) { + @RequestMapping(path = "/displayHeaderInfo.do") + public void displayHeaderInfo(**@CookieValue(name = "JSESSIONID")** String cookie) { //... } ---- @@ -2027,9 +2027,9 @@ The following code sample demonstrates how to get the value of the `Accept-Encod [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping("/displayHeaderInfo.do") - public void displayHeaderInfo(**@RequestHeader("Accept-Encoding")** String encoding, - **@RequestHeader("Keep-Alive")** long keepAlive) { + @RequestMapping(path = "/displayHeaderInfo.do") + public void displayHeaderInfo(**@RequestHeader(name = "Accept-Encoding")** String encoding, + **@RequestHeader(name = "Keep-Alive")** long keepAlive) { //... } ---- @@ -2046,7 +2046,7 @@ with all header values. ==== Built-in support is available for converting a comma-separated string into an array/collection of strings or other types known to the type conversion system. For -example a method parameter annotated with `@RequestHeader("Accept")` may be of type +example a method parameter annotated with `@RequestHeader(name = "Accept")` may be of type `String` but also `String[]` or `List`. ==== @@ -2181,7 +2181,7 @@ Both `@ControllerAdvice` and `@RestControllerAdvice` can target a subset of cont public class AnnotationAdvice {} // Target all Controllers within specific packages - @ControllerAdvice("org.example.controllers") + @ControllerAdvice(basePackages = "org.example.controllers") public class BasePackageAdvice {} // Target all Controllers assignable to specific classes @@ -2210,7 +2210,7 @@ the view class or interface to be used: @RestController public class UserController { - @GetMapping("/user") + @GetMapping(path = "/user") @JsonView(User.WithoutPasswordView.class) public User getUser() { return new User("eric", "7!jd#h23"); @@ -2262,7 +2262,7 @@ to the model: @Controller public class UserController extends AbstractController { - @GetMapping("/user") + @GetMapping(path = "/user") public String getUser(Model model) { model.addAttribute("user", new User("eric", "7!jd#h23")); model.addAttribute(JsonView.class.getName(), User.WithoutPasswordView.class); @@ -2332,7 +2332,7 @@ of such a controller method: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping("/quotes") + @RequestMapping(path = "/quotes") @ResponseBody public DeferredResult quotes() { DeferredResult deferredResult = new DeferredResult(); @@ -2444,7 +2444,7 @@ Here is an example of that: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping("/events") + @RequestMapping(path = "/events") public ResponseBodyEmitter handle() { ResponseBodyEmitter emitter = new ResponseBodyEmitter(); // Save the emitter somewhere.. @@ -2503,7 +2503,7 @@ Here is an example of that: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping("/download") + @RequestMapping(path = "/download") public StreamingResponseBody handle() { return new StreamingResponseBody() { @Override @@ -3007,7 +3007,7 @@ through `Model` nor `RedirectAttributes`. For example: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @PostMapping("/files/{path}") + @PostMapping(path = "/files/{path}") public String upload(...) { // ... return "redirect:files/{path}"; @@ -3179,7 +3179,7 @@ application/atom+xml is shown below. private List contentList = new ArrayList(); - @GetMapping("/content") + @GetMapping(path = "/content") public ModelAndView getContent() { ModelAndView mav = new ModelAndView(); mav.setViewName("content"); @@ -3324,10 +3324,10 @@ Spring MVC also provides a mechanism for building links to controller methods. F [subs="verbatim,quotes"] ---- @Controller - @RequestMapping("/hotels/{hotel}") + @RequestMapping(path = "/hotels/{hotel}") public class BookingController { - @GetMapping("/bookings/{booking}") + @GetMapping(path = "/bookings/{booking}") public String getBooking(@PathVariable Long booking) { // ... @@ -3418,10 +3418,10 @@ For example given: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping("/people/{id}/addresses") + @RequestMapping(path = "/people/{id}/addresses") public class PersonAddressController { - @RequestMapping("/{country}") + @RequestMapping(path = "/{country}") public HttpEntity getAddress(@PathVariable String country) { ... } } ---- @@ -3792,9 +3792,9 @@ use `MultipartHttpServletRequest` or `MultipartFile` in the method parameters: @Controller public class FileUploadController { - @PostMapping("/form") - public String handleFormUpload(@RequestParam("name") String name, - @RequestParam("file") MultipartFile file) { + @PostMapping(path = "/form") + public String handleFormUpload(@RequestParam(name = "name") String name, + @RequestParam(name = "file") MultipartFile file) { if (!file.isEmpty()) { byte[] bytes = file.getBytes(); @@ -3821,9 +3821,9 @@ the method parameter: @Controller public class FileUploadController { - @PostMapping("/form") - public String handleFormUpload(@RequestParam("name") String name, - @RequestParam("file") Part file) { + @PostMapping(path = "/form") + public String handleFormUpload(@RequestParam(name = "name") String name, + @RequestParam(name = "file") Part file) { InputStream inputStream = file.getInputStream(); // store bytes from uploaded file somewhere @@ -3865,7 +3865,7 @@ Content-Transfer-Encoding: 8bit ... File Data ... ---- -You could access the part named "meta-data" with a `@RequestParam("meta-data") String +You could access the part named "meta-data" with a `@RequestParam(name = "meta-data") String metadata` controller method argument. However, you would probably prefer to accept a strongly typed object initialized from the JSON formatted data in the body of the request part, very similar to the way `@RequestBody` converts the body of a @@ -3879,9 +3879,9 @@ multipart: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @PostMapping("/someUrl") - public String onSubmit(**@RequestPart("meta-data") MetaData metadata, - @RequestPart("file-data") MultipartFile file**) { + @PostMapping(path = "/someUrl") + public String onSubmit(**@RequestPart(name = "meta-data") MetaData metadata, + @RequestPart(name = "file-data") MultipartFile file**) { // ... @@ -3889,7 +3889,7 @@ multipart: ---- Notice how `MultipartFile` method arguments can be accessed with `@RequestParam` or with -`@RequestPart` interchangeably. However, the `@RequestPart("meta-data") MetaData` method +`@RequestPart` interchangeably. However, the `@RequestPart(name = "meta-data") MetaData` method argument in this case is read as JSON content based on its `'Content-Type'` header and converted with the help of the `MappingJackson2HttpMessageConverter`. @@ -4493,7 +4493,7 @@ in responses like this: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @GetMapping("/book/{id}") + @GetMapping(path = "/book/{id}") public ResponseEntity showBook(@PathVariable Long id) { Book book = findBook(id); diff --git a/src/asciidoc/web-view.adoc b/src/asciidoc/web-view.adoc index a52bb9352c3..2460d181066 100644 --- a/src/asciidoc/web-view.adoc +++ b/src/asciidoc/web-view.adoc @@ -1774,7 +1774,7 @@ handler method being defined like so... @Controller public class XsltController { - @RequestMapping("/") + @RequestMapping(path = "/") public String home(Model model) throws Exception { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); diff --git a/src/asciidoc/web-websocket.adoc b/src/asciidoc/web-websocket.adoc index 56cb79b2e3a..315cfbc220b 100644 --- a/src/asciidoc/web-websocket.adoc +++ b/src/asciidoc/web-websocket.adoc @@ -1411,7 +1411,7 @@ type, for example: this.template = template; } - @RequestMapping(path="/greetings", method=POST) + @RequestMapping(path = "/greetings", method=POST) public void greet(String greeting) { String text = "[" + getTimestamp() + "]:" + greeting; this.template.convertAndSend("/topic/greetings", text);