...
RequestMappingHandlerMapping - Mapped "{[/searchModel],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String CLASS_NAME.METHOD()
...
[main] org.apache.catalina.startup.Catalina.start Server startup in 16212 ms
...
RequestMappingHandlerMapping : Looking up handler method for path /searchModel
RequestMappingHandlerMapping : Did not find handler method for [/searchModel]
...
是否存在配置缺失的问题,或者我的代码更深入?
控制器代码
@Controller
public class SearchModelController {
...
@Autowired
private SearchModelDAO searchModelDAO;
...
@RequestMapping(value = "/searchModel", method = RequestMethod.GET)
public String METHOD()
{
return "searchModelForm.html";
}
...
除了方法和两个@Autowired之外,控制器的代码并不多。完成所有必要的导入。
应用程序main用
定义@SpringBootApplication
public class Application extends SpringBootServletInitializer
{
@SuppressWarnings("resource")
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
{
new ClassPathXmlApplicationContext("CONTEXT.xml");
return application.sources(Application.class);
}
CONTEXT.xml
<!-- <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<context:component-scan base-package="..., ..., ..."/>
<context:annotation-config/>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
<tx:annotation-driven transaction-manager="transactionManager"/>
...
web.xml是
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>...</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</context-param>
代码在Eclipse下用Maven编译并生成WAR包。然后我把.war放在apache webapps目录下并启动apache。
谢谢