Java servlet.PageNotFound:在DispatcherServlet中找不到URI为的HTTP请求的映射
我正在使用SpringMVC创建RESTAPI端点。 当我尝试访问Java servlet.PageNotFound:在DispatcherServlet中找不到URI为的HTTP请求的映射,java,spring,jakarta-ee,spring-mvc,Java,Spring,Jakarta Ee,Spring Mvc,我正在使用SpringMVC创建RESTAPI端点。 当我尝试访问时,我遇到了404 not Found”http://localhost:8080/myapp/heroku/resources“ 我在服务器日志中有以下内容: WARN servlet.PageNotFound:在DispatcherServlet中找不到URI为[/myapp/heroku/resources]的HTTP请求的映射 @Controller public class HerokuController { @
时,我遇到了404 not Found”http://localhost:8080/myapp/heroku/resources“
我在服务器日志中有以下内容:
WARN servlet.PageNotFound:在DispatcherServlet中找不到URI为[/myapp/heroku/resources]的HTTP请求的映射
@Controller
public class HerokuController {
@RequestMapping(value = "/heroku/resources/", method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<JSONObject> provision(@RequestBody JSONObject body){
JSONObject response = new JSONObject();
JSONObject config_vars = new JSONObject();
/*code*/
return new ResponseEntity<JSONObject>(response,HttpStatus.OK);
}
@控制器
公共类控制器{
@RequestMapping(value=“/heroku/resources/”,method=RequestMethod.POST,products=MediaType.APPLICATION\u JSON\u value)
公共响应提供(@RequestBody JSONObject body){
JSONObject响应=新建JSONObject();
JSONObject config_vars=新JSONObject();
/*代码*/
返回新的ResponseEntity(response,HttpStatus.OK);
}
有什么问题吗?我确实使用和扫描所有控制器。
谢谢
servlet-context.xml
<beans:import resource="classpath:spring-properties-loader.xml"/>
<!-- To be able to aop controllers -->
<aop:aspectj-autoproxy proxy-target-class="true" />
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- The HandlerMapping for JSONP requests. -->
<beans:bean class="com.datapine.controllers.jsonp.JsonpHandlerMapping" />
<!-- For uploading files -->
<beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<beans:property name="maxUploadSize" value="${csv.maxsize.file}"/>
</beans:bean>
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
<beans:property name="order">
<beans:value>2</beans:value>
</beans:property>
</beans:bean>
<context:component-scan
base-package="com.datapine.download.controller,
com.datapine.controllers,
com.datapine.controller
com.datapine.payment.controller" />
<!-- json -->
<beans:bean id="xmlFileViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
<beans:property name="location">
<beans:value>/WEB-INF/views.xml</beans:value>
</beans:property>
<beans:property name="order">
<beans:value>1</beans:value>
</beans:property>
</beans:bean>
2.
/WEB-INF/views.xml
1.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
classpath:spring-properties-loader.xml
classpath:monitoring-spring.xml
classpath:spring-security.xml
classpath:domain-security.xml
classpath:spring-mail.xml
classpath:spring-context.xml
classpath:smart_chart-db-config.xml
classpath:logging-aop-context.xml
classpath:salesforce-aop-context.xml
classpath:jms-extractor-producer-activemq.xml
</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>db_profile,db_mysql</param-value>
</context-param>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/appServlet/servlet-context.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<servlet-name>appServlet</servlet-name>
</filter-mapping>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Monitoring -->
<filter>
<filter-name>monitoring</filter-name>
<filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
<async-supported>true</async-supported>
<!-- TO ENABLE LOGS -->
<!-- <init-param> -->
<!-- <param-name>log</param-name> -->
<!-- <param-value>true</param-value> -->
<!-- </init-param> -->
</filter>
<filter-mapping>
<filter-name>monitoring</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>net.bull.javamelody.SessionListener</listener-class>
</listener>
<!-- <filter> -->
<!-- <filter-name>XssFilter</filter-name> -->
<!-- <filter-class>com.datamint.utils.XssFilter</filter-class> -->
<!-- </filter> -->
<!-- <filter-mapping> -->
<!-- <filter-name>XssFilter</filter-name> -->
<!-- <url-pattern>/*</url-pattern> -->
<!-- </filter-mapping> -->
</web-app>
上下文配置位置
/WEB-INF/spring/root-context.xml
类路径:spring-properties-loader.xml
类路径:monitoring-spring.xml
类路径:spring-security.xml
类路径:domain-security.xml
类路径:spring-mail.xml
类路径:spring-context.xml
类路径:smart_chart-db-config.xml
类路径:logging-aop-context.xml
类路径:salesforce-aop-context.xml
类路径:jms-extractor-producer-activemq.xml
spring.profiles.active
数据库配置文件,数据库mysql
org.springframework.security.web.session.HttpSessionEventPublisher
org.springframework.web.context.ContextLoaderListener
appServlet
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/spring/appServlet/servlet-context.xml
1.
appServlet
/
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
appServlet
编码滤波器
org.springframework.web.filter.CharacterEncodingFilter
编码
UTF-8
强制编码
真的
编码滤波器
/*
监测
net.bull.javamelody.MonitoringFilter
真的
监测
/*
net.bull.javamelody.SessionListener
包com.datapine.controllers.jsonp
公共类JsonpHandlerMapping扩展了RequestMappingHandlerMapping{
private boolean useSuffixPatternMatch = true;
private boolean useTrailingSlashMatch = true;
@Override
protected boolean isHandler(final Class<?> beanType) {
boolean result = true;
result &= AnnotationUtils.findAnnotation(beanType, Jsonp.class) != null;
result &= super.isHandler(beanType);
return result;
}
@Override
protected RequestMappingInfo getMappingForMethod(final Method method,
final Class<?> handlerType) {
RequestMappingInfo info = null;
RequestMapping methodAnnotation = AnnotationUtils.findAnnotation(
method, RequestMapping.class);
final JsonpMethod methodJsonpAnnotation = AnnotationUtils
.findAnnotation(method, JsonpMethod.class);
final Jsonp jsonpAnnotation = AnnotationUtils.findAnnotation(
handlerType, Jsonp.class);
if (methodAnnotation != null && methodJsonpAnnotation != null) {
RequestCondition<?> methodCondition = getCustomMethodCondition(method);
info = createRequestMappingInfo(methodAnnotation, methodCondition,
jsonpAnnotation);
// RequestMapping typeAnnotation = AnnotationUtils.findAnnotation(
// handlerType, RequestMapping.class);
// if (typeAnnotation != null) {
// RequestCondition<?> typeCondition =
// getCustomTypeCondition(handlerType);
// info = createRequestMappingInfo(typeAnnotation, typeCondition,
// jsonpAnnotation).combine(info);
// }
}
return info;
}
private RequestMappingInfo createRequestMappingInfo(
RequestMapping annotation, RequestCondition<?> customCondition,
Jsonp jsonpAnnotation) {
ArgumentUtil.assertTrue(annotation.method().length == 1);
final String[] paths = annotation.value();
final String pattern = jsonpAnnotation.value();
final PatternsRequestCondition patterns = new PatternsRequestCondition(
paths(paths, pattern), getUrlPathHelper(), getPathMatcher(),
this.useSuffixPatternMatch, this.useTrailingSlashMatch);
final RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition(
RequestMethod.GET);
final String[] additionalParams;
final RequestMethod methodMethod = annotation.method()[0];
if (methodMethod == RequestMethod.GET) {
additionalParams = new String[] { "callback",
"_method=" + methodMethod.name() };
} else {
additionalParams = new String[] { "callback",
"_method=" + methodMethod.name(), "_payload" };
}
final ParamsRequestCondition params = new ParamsRequestCondition(
append(annotation.params(), additionalParams));
final HeadersRequestCondition headers = new HeadersRequestCondition(
annotation.headers());
final ProducesRequestCondition produces = new ProducesRequestCondition(
annotation.produces(), annotation.headers());
final ConsumesRequestCondition consumes = new ConsumesRequestCondition(
annotation.consumes(), annotation.headers());
final RequestMappingInfo result = new RequestMappingInfo(patterns,
methods, params, headers, consumes, produces, customCondition);
return result;
}
private <T> T[] append(final T[] head, final T[] tail) {
@SuppressWarnings("unchecked")
final T[] result = (T[]) Array.newInstance(head.getClass()
.getComponentType(), head.length + tail.length);
System.arraycopy(head, 0, result, 0, head.length);
System.arraycopy(tail, 0, result, head.length, tail.length);
return result;
}
private String[] paths(final String[] values, final String pattern) {
final String[] result = new String[values.length];
for (int index = 0; index < values.length; ++index) {
final String value = values[index];
final String resultItem = pattern.replaceAll("\\{value\\}", value);
result[index] = resultItem;
}
return result;
}
private boolean useSuffixPatternMatch=true;
私有布尔useTrailingSlashMatch=true;
@凌驾
受保护的布尔isHandler(最终类beanType){
布尔结果=真;
结果&=AnnotationUtils.findAnnotation(beanType,Jsonp.class)!=null;
结果&=super.isHandler(beanType);
返回结果;
}
@凌驾
受保护的RequestMappingInfo GetMappingFormMethod(最终方法,
最终类(手动类型){
RequestMappingInfo=null;
RequestMapping methodAnnotation=AnnotationUtils.findAnnotation(
方法,RequestMapping.class);
最终JsonpMethod方法JsonPanNotation=AnnotationUtils
.findAnnotation(方法,JsonpMethod.class);
final Jsonp jsonpAnnotation=AnnotationUtils.findAnnotation(
handlerType,Jsonp.class);
if(methodAnnotation!=null&&methodJsonpAnnotation!=null){
RequestCondition methodCondition=getCustomMethodCondition(方法);
info=createRequestMappingInfo(methodAnnotation、methodCondition、,
JSONPAN标记法);
//RequestMapping typeAnnotation=AnnotationUtils.findAnnotation(
//handlerType,RequestMapping.class);
//if(typeAnnotation!=null){
//请求条件类型条件=
//getCustomTypeCondition(handlerType);
//info=createRequestMappingInfo(类型注释、类型条件、,
//jsonpAnnotation)。合并(信息);
// }
}
退货信息;
}
私有RequestMappingInfo createRequestMappingInfo(
RequestMapping注释,RequestCondition customCondition,
Jsonp(JSONPAN表示法){
ArgumentUtil.assertTrue(annotation.method().length==1);
最终字符串[]路径=annotation.value();
最终字符串模式=jsonpAnnotation.value();
最终模式请求条件模式=新模式请求条件(
路径(路径,模式),getUrlPathHelper(),getPathMatcher(),
this.useSuffiblExpatterMatch,this.useTrailingSlashMatch);
final RequestMethodsRequestCondition methods=新的RequestMethodsRequestCondition(
请求方法(GET);
最终字符串[]附加参数;
final RequestMethod=annotation.method()[0];
if(methodMethod==RequestMethod.GET){
additionalParams=新字符串[]{“回调”,
“_method=“+methodMethod.name()”;
}否则{
additionalParams=新字符串[]{“回调”,
“_-method=“+methodMethod.name(),”_-payload“};
}
最终参数requestcondition params=新参数requestcondition(
追加(annotation.params(),additionalParams));
最终HeaderRequestCondition headers=新HeaderRequests