感谢各位大佬过来给建议,我看我的配置应该没问题,555
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/springApplocation.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatchServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/springApplocation-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatchServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--注解驱动-->
<mvc:annotation-driven/>
<!--包扫描-->
<context:component-scan base-package="cn.sty.test.controller"/>
<!--视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/html"/>
<property name="suffix" value=".html"/>
</bean>
@Controller
public class UserServlet {
@RequestMapping(value = "/regist", method = RequestMethod.GET)
public String regist(){
System.out.println("我进来了");
return "index";
}
}
```
UserServlet 所在的 包路径有没有添加到 spring 扫描包路径下呢?
配置tomcat的时候 有没有加应用名?