-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中使用'',但似乎我看不到它。 –