Ich habe die folgende Projektstruktur:Frühling Webkontext Pfadkonfiguration
src/main/resources/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/webapp/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>
Und src/webapp/WEB-INF/Frühjahr/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>
Every gut für mich sieht, mit der Ausnahme, dass, wenn ich den Krieg in tomcat Behälter setzen und rufen http://localhost:8080/bet-manager-api/hello i bekommen 404. TestCotroller Klasse:
@RestController
@RequestMapping(value = "/hello")
public class TestController {
@Autowired
private TestService testService;
@RequestMapping(method = RequestMethod.GET)
public void hello() {
testService.doSomethink();
}
}
. Auch in der pom.xml im Build-Bereich habe ich den endgültigen Namen auf "bet-manager-api" gesetzt. Was mache ich falsch? Und warum gibt es auch keine Protokollierung? Ich überprüfe alle Protokolle in tomcat/logs/aber ich fand keine wichtigen Protokolle. Danke
Welche Protokolldateien haben Sie überprüft? Sie sollten dort zumindest etwas sehen. Könnten Sie den Inhalt der Protokolldatei einfügen? –
In catalina.out ist Server-Start-Logging und in localhost_acess_log ist die Anfrage 0: 0: 0: 0: 0: 0: 0: 1 - - [13/Jul/2016: 15: 04: 01 +0300] "GET/bet-manager-api/hallo HTTP/1.1 "404 993 –
catalina.out sollte auch die Startprotokolle von Spring enthalten –