Cam*_*ego 6 java spring servlets spring-mvc
早上,我已经检查了这个问题的大多数答案(在带有名称的DispatcherServlet中找不到带有URI的HTTP请求的映射)以及在DispatcherServlet中找不到带有URI [/ ChickenTest/index]的HTTP请求的映射名称'dispatcherServlet')但我仍然得到"在DispatcherServlet中找不到带有URI [/ bmoa-surrounds/bmoa]的HTTP请求的映射,名称为'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>
Run Code Online (Sandbox Code Playgroud)
然后是我的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>
Run Code Online (Sandbox Code Playgroud)
我的春天配置文件
<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>
Run Code Online (Sandbox Code Playgroud)
最后我的控制器
@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));
}
Run Code Online (Sandbox Code Playgroud)
我正在调用"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
Run Code Online (Sandbox Code Playgroud)
还有这个
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'
Run Code Online (Sandbox Code Playgroud)
不是最后一个意味着映射加载?请帮忙 ;(
我现在感觉真的很愚蠢......一开始(感谢 Angad 提供的线索),url 模式是错误的,它应该指向 servlet,而且,加载的 bean 是 BMOAServlet 而不是 bmoa,所以当我更改了 url-patter no 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>
Run Code Online (Sandbox Code Playgroud)
和 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));
}
Run Code Online (Sandbox Code Playgroud)
现在一切顺利,我还像这样更改了 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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
64588 次 |
| 最近记录: |