我有以下项目结构:春季Web上下文路径配置
的src /主/资源/ META-INF/applicationContext.xml的
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.bet.manager.services"/>
</beans:beans>
的src/web应用/网络。 xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/applicationContext.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>bet-manager-api</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>bet-manager-api</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
and src/webapp/WEB-INF/spring/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven/>
<context:component-scan base-package="com.bet.manager.web"/>
<mvc:default-servlet-handler/>
</beans:beans>
当我把战争在Tomcat容器,并呼吁http://localhost:8080/bet-manager-api/hello Everythink我看起来不错,但我得到404 TestCotroller类:
@RestController
@RequestMapping(value = "/hello")
public class TestController {
@Autowired
private TestService testService;
@RequestMapping(method = RequestMethod.GET)
public void hello() {
testService.doSomethink();
}
}
。同样在构建部分的pom.xml中,我将最终名称设置为“bet-manager-api”。什么即时做错了?还有为什么theres没有日志记录?我检查了tomcat/logs /中的所有日志,但没有发现任何重要的日志。谢谢
你检查过哪些日志文件?你至少应该看到一些输出。你能粘贴日志文件内容吗? –
catalina.out是服务器启动日志记录,在localhost_acess_log中是请求0:0:0:0:0:0:1 - [13/Jul/2016:15:04:01 +0300]“GET/bet-manager-api/hello HTTP/1.1“404 993 –
catalina.out还应该包含Spring的启动日志 –