早上,我已经检查了这个问题的大部分答案(No mapping found for HTTP request with URI.... in DispatcherServlet with name)和(No mapping found for HTTP request with URI [/ChickenTest/index] in DispatcherServlet with name 'dispatcherServlet'),但我仍然得到“没有找到带URI的HTTP请求的映射[/ bmoa-在DispatcherServlet中使用名称为“bmoa”的环绕/ bmoa,所以,任何帮助都应该是apreciated:
POM:
<dependencies>
<!-- Junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- Testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<!-- Log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
然后是我的web.xml
<display-name>bmoa-surrounds</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/bmoa-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>bmoa</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>bmoa</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
我的春季配置文件
<context:component-scan base-package="xxxx"/>
<context:annotation-config/>
<context:spring-configured/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
最后是我的控制器
@Controller
public class BMOAServlet implements HttpRequestHandler {
/**
*
*/
@RequestMapping("/bmoa-surrounds/bmoa")
public void handleRequest(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
IOException {
response.getWriter().write("result=" + handleIncomingMessage(request));
}
我正在调用“http:// localhost:8080 / bmoa-surrounds / bmoa?juan = 9898”,但我仍然认为在DispatcherServlet中找不到带有URI [/ bmoa-surrounds / bmoa]的HTTP请求的映射名字'bmoa',任何想法?我的环境是java6,部署到jboss
我也确定bean是beign加载的,我在服务器日志中得到了这个
12:34:06,671 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-5) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@57ffa0: defining beans [BMOABussinesDelegate,properties,BMOAServlet,.........]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@122d7c6
还有这个
12:34:06,753 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa] onto handler 'BMOAServlet' 12:34:06,754 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa.*] onto handler 'BMOAServlet' 12:34:06,755 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa/] onto handler 'BMOAServlet'
不是最后一个意味着映射被加载?请帮忙;(
答案 0 :(得分:3)
我现在感觉真的很蠢....起初(感谢线索Angad),url-pattern错了,它应该指向servlet,而且,加载的bean是BMOAServlet而不是bmoa ,所以当我更改了url-patter没有bmoa,设法看到错误,最后我的web.xml需要看起来像这样:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/bmoa-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>bmoa</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>bmoa</servlet-name>
<url-pattern>/bmoa</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
和这样的bean类:
@Controller("bmoa")
public class BMOAServlet implements HttpRequestHandler {
/**
*
*/
@RequestMapping("/bmoa-surrounds/bmoa")
public void handleRequest(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
IOException {
response.getWriter().write("result=" + handleIncomingMessage(request));
}
现在一切顺利,我也改变了这样的servlet类:
<servlet>
<servlet-name>bmoa</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
答案 1 :(得分:0)
检查此配置文件:src \ main \ webapp \ WEB-INF \ spring \ appServlet \ controllers.xml
内容如下:
<context:component-scan base-package="org.springframework.samples.mvc" />
是你的控制器&#34; org.springframework.samples.mvc&#34;?
答案 2 :(得分:-1)
在pom.xml中,确保打包设置为war
,如<packaging>war</packaging>
,而不是jar或其他任何东西。