SpringMVC configuration controller
SpringMVC controller configuration relative Spring Boot a bit more complex
applicationContext.xml
Add the following configuration applicationContext.xml
- context:component-scan
Scan base-package package following @Component @Service the like, loaded container management Sping
- mvc:annotation-driven
Annotation-driven
<!--包扫描-->
<context:component-scan base-package="com.jsong.wiki.shiro"/>
<!-- 注释-->
<mvc:annotation-driven/>
web.xml
web.xml configuration servlet
loaded applicationContext configuration files, configuration mapping
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:conf/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
java
This part of the normal spring boot on and as the project
@RestController
@RequestMapping("/shiro")
public class ShiroController {
// @RequiresRoles("admin")
@RequestMapping("/hello")
public String getHello() {
return "Hello World";
// return "../index";
}
}
After restarting, the controller can access the
http: // localhost: 8080 / shiro / hello