我有以下项目结构:
的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应用/ 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>
和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>
Everythink对我来说看起来很好,除了当我把战争放在tomcat容器中并打电话给http://localhost:8080/bet-manager-api/hello时我得到404。 TestCotroller类:
@RestController
@RequestMapping(value = "/hello")
public class TestController {
@Autowired
private TestService testService;
@RequestMapping(method = RequestMethod.GET)
public void hello() {
testService.doSomethink();
}
}
。同样在构建部分的pom.xml中,我将最终名称设置为&#34; bet-manager-api&#34;。我做错了什么?还有为什么没有伐木?我检查tomcat / logs /中的所有日志,但我没有找到任何重要的日志。感谢
答案 0 :(得分:0)
配置方面的一切看起来都很好,是的。尝试在src / webapp / WEB-INF / spring / applicationContext.xml中添加<context:annotation-config/>
,但它不应该导致问题。