-1
我使用spring 4.2.2.RELEASE
hibernate 5.0.2.Final
創建了一個應用程序,併成功將此應用程序部署到jboss 7.1.1。我啓用了日誌級別DEBUG,以便我可以看到發生了什麼情況,並根據日誌成功部署應用程序。Spring 4.2調度程序servlet 404錯誤
戰爭文件的名稱是mycompany.war
因此它部署在上下文路徑/mycompany
。
我
04:30:18,975 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http--127.0.0.1-8080-1) DispatcherServlet with name 'dispatcher' processing POST request for [/mycompany/campaigns]
04:30:18,975 WARN [org.springframework.web.servlet.PageNotFound] (http--127.0.0.1-8080-1) No mapping found for HTTP request with URI [/mycompany/campaigns] in DispatcherServlet with name 'dispatcher'
04:30:18,976 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http--127.0.0.1-8080-1) Successfully completed request
下面像下面
@RestController
public class AbcController {
@RequestMapping(value = "/campaigns", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
public Campaign addCampaign(@RequestBody Campaign campaign) throws ServiceException {
return campaignService.addCampaign(campaign);
}
}
現在,當我使用的郵遞員發送請求到localhost:8080/mycompany/campaigns
我收到404錯誤與下面的調試日誌控制器類是web.xml
文件
<?xml version="1.0" encoding="UTF-8" ?>
<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_3_0.xsd"
version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>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>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
以下是application-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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<tx:annotation-driven/>
<context:component-scan base-package="com.mycompany"/>
<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath*:META-INF/jpa-persistence.xml"/>
<property name="persistenceUnitName" value="MainPU" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="myEmf"/>
</bean>
<bean id="persistenceExceptionTranslationPostProcessor" class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
</beans>
爲什麼我面臨這個問題?我檢查了完整的日誌,在日誌中沒有異常沒有錯誤。另外,我可以看到我的控制器在春季初始化。
在INFO級別打開Spring日誌並檢查哪些請求處理程序已註冊。 –
我懷疑問題來自您的Web應用程序的上下文根。你是怎麼做的,你爲webapp上下文根設置了什麼?在JBoss中,通過在google中進行簡單檢查,似乎取決於您的EAR的'application.xml','WEB-INF/jboss-web.xml'或WAR文件名。確保前者2不存在,這樣您的上下文根就是您的WAR名稱。 –
哦,發現另一個問題:我相信你應該在應用上下文xml中使用'',但似乎我看不到它。 –