...
Code Block |
---|
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.3.xsd"
^^^^^ NO!!!
|
Web/Controllers
- In a Spring MVC web application, controller classes should not extend any Spring framework classes.
- Controller classes should be identified to Spring as a controller bean by using the @Controller annotation.
- Request URLs should be mapped to controller classes and methods by using the @RequestMapping annotation.
- Generally speaking, we aim to configure controllers by using annotations.
- We should use the @Autowired annotation for injected dependencies.
- As controllers are typically configured as singletons in the Spring context, the classes should be thread-safe. In practical terms, this means fields, or instance variables, should never maintain any state, and they should not be instantiated by the new operator. The only instance variables in a controller should be other Spring beans, injected by the Spring container. Typically these will be service classes or helper classes.
- Controllers should not contain any business logic - they should be concerned with UI-related logic. Business logic should be delegated to service classes.
...