- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
长话短说:我有正确处理请求的 MVC servlet,但 REST servlet 似乎根本不处理任何请求。就像它不存在一样,或者请求以某种方式不匹配。
更多详情:
我的spring版本是4.2.1。
我有一个使用 Spring MVC 的应用程序,它已经可以运行了。问题是第二个 servlet,我想添加它,以便它处理 REST 请求。
这是 web.xml
之前我尝试将 REST servlet 添加到其中(因此到目前为止一切正常):
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>My app</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/core-context.xml /WEB-INF/spring-security.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet-mapping>
<servlet-name>AccServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.do</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>RestServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
</web-app>
简而言之 - 所有请求 *.do
将由 MVC servlet 处理,一般所有请求都将通过 Spring Security。
我有一个简单的 MVC Controller 来处理:
@Controller
public class JspController {
@Autowired
private UserService userService;
@RequestMapping(value = "/index.do", method = RequestMethod.GET)
public String provideIndexModel(ModelMap model) {
User user = userService.getLoggedUser();
model.addAttribute("user", user.getUsername());
if (user.getBusiness() != null) {
model.addAttribute("business", user.getBusiness().getCompanyName());
}
return "index";
}
@RequestMapping(value = "/login.do", method = {RequestMethod.GET})
public String provideLoginModel(ModelMap model) {
return "login";
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
}
Controller 位于通过 servlet 上下文 xml 文件中的适当扫描声明扫描的包中。
现在,我为启用 REST 所做的是将以下 servlet 添加到 web.xml
:
<servlet>
<servlet-name>AccServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>*.rest</url-pattern>
</servlet-mapping>
然后我创建了另一个 servlet 上下文文件 RestServlet-servlet.xml
,我把 <context:component-scan base-package="my.app.rest"/>
放在哪里- 这就是包,然后我将 RestController 放在那里,如下所示:
@RestController
public class RestService {
public RestService() {
System.out.println("yes!");
}
@RequestMapping(value = "/user.rest", method = RequestMethod.GET)
public String getUser() {
return "abc";
}
}
rest Controller 确实已创建(我调试了构造函数),因此 spring 确实看到了它,但是当我尝试从 Postman(Chrome 扩展)调用它时,我收到 404 响应。我的请求是 URL:localhost:8080/acc/user.rest
(其中 acc
是我的应用名称)。
为什么我的电话匹配*.rest
没有被重定向到正确的 Controller ? (我试图在调试中停在那里 - 它从未被调用过)。
编辑 1:
这是我当前的完整 web.xml:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>My app</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/core-context.xml /WEB-INF/spring-security.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet-mapping>
<servlet-name>AccServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.do</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>AccServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RestServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
</web-app>
这是我的 core-context.xml:
<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:component-scan base-package="my.app">
<context:exclude-filter expression="org.springframework.stereotype.Controller"
type="annotation" />
</context:component-scan>
<bean id="accDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost/acc" />
<property name="username" value="acc" />
</bean>
<bean id="accSessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="accDataSource" />
<property name="packagesToScan">
<list>
<value>my.app.entities</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.PostgreSQL92Dialect
</value>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="accSessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
</beans>
这是 AccServlet-servlet.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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="my.app.web"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
这是我的 RestServlet-servlet.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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="my.app.rest"/>
</beans>
我有 @Controller
用于 my.app.web
中的 MVC我有 @RestController
在 my.app.rest
.
来自 tomcat 的日志:
20-Oct-2015 14:00:16.096 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.23
20-Oct-2015 14:00:16.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: May 19 2015 14:58:38 UTC
20-Oct-2015 14:00:16.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.23.0
20-Oct-2015 14:00:16.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
20-Oct-2015 14:00:16.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 3.14.33
20-Oct-2015 14:00:16.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
20-Oct-2015 14:00:16.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib64/java/jre
20-Oct-2015 14:00:16.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_45-b14
20-Oct-2015 14:00:16.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
20-Oct-2015 14:00:16.098 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
20-Oct-2015 14:00:16.174 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
20-Oct-2015 14:00:16.183 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
20-Oct-2015 14:00:16.184 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
20-Oct-2015 14:00:16.185 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
20-Oct-2015 14:00:16.185 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 297 ms
20-Oct-2015 14:00:16.200 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
20-Oct-2015 14:00:16.200 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.23
20-Oct-2015 14:00:16.213 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /home/googie/projects/tomcat/webapps/acc.war
20-Oct-2015 14:00:16.951 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
20-Oct-2015 14:00:16.968 INFO [localhost-startStop-1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization started
20-Oct-2015 14:00:17.012 INFO [localhost-startStop-1] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing Root WebApplicationContext: startup date [Tue Oct 20 14:00:17 CEST 2015]; root of context hierarchy
20-Oct-2015 14:00:17.031 INFO [localhost-startStop-1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/core-context.xml]
20-Oct-2015 14:00:17.149 INFO [localhost-startStop-1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-security.xml]
20-Oct-2015 14:00:17.176 INFO [localhost-startStop-1] org.springframework.security.core.SpringSecurityCoreVersion.performVersionChecks You are running with Spring Security Core 4.0.2.RELEASE
20-Oct-2015 14:00:17.178 INFO [localhost-startStop-1] org.springframework.security.config.SecurityNamespaceHandler.<init> Spring Security 'config' module version is 4.0.2.RELEASE
20-Oct-2015 14:00:17.197 INFO [localhost-startStop-1] org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser.parseInterceptUrlsForFilterInvocationRequestMap Creating access control expression attribute 'hasRole('ROLE_USER')' for /**
20-Oct-2015 14:00:17.231 INFO [localhost-startStop-1] org.springframework.security.config.http.HttpSecurityBeanDefinitionParser.checkFilterChainOrder Checking sorted filter chain: [Root bean: class [org.springframework.security.web.context.SecurityContextPersistenceFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 200, Root bean: class [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 400, Root bean: class [org.springframework.security.web.header.HeaderWriterFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 500, Root bean: class [org.springframework.security.web.authentication.logout.LogoutFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 700, <org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0>, order = 1100, Root bean: class [org.springframework.security.web.authentication.www.BasicAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1500, Root bean: class [org.springframework.security.web.savedrequest.RequestCacheAwareFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1600, Root bean: class [org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1700, Root bean: class [org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1900, Root bean: class [org.springframework.security.web.authentication.AnonymousAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 2000, Root bean: class [org.springframework.security.web.session.SessionManagementFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 2100, Root bean: class [org.springframework.security.web.access.ExceptionTranslationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 2200, <org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0>, order = 2300]
20-Oct-2015 14:00:17.489 INFO [localhost-startStop-1] org.hibernate.Version.logVersion HHH000412: Hibernate Core {5.0.2.Final}
20-Oct-2015 14:00:17.490 INFO [localhost-startStop-1] org.hibernate.cfg.Environment.<clinit> HHH000206: hibernate.properties not found
20-Oct-2015 14:00:17.491 INFO [localhost-startStop-1] org.hibernate.cfg.Environment.buildBytecodeProvider HHH000021: Bytecode provider name : javassist
20-Oct-2015 14:00:17.521 INFO [localhost-startStop-1] org.hibernate.annotations.common.reflection.java.JavaReflectionManager.<clinit> HCANN000001: Hibernate Commons Annotations {5.0.0.Final}
20-Oct-2015 14:00:17.613 INFO [localhost-startStop-1] org.hibernate.dialect.Dialect.<init> HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL92Dialect
20-Oct-2015 14:00:17.704 INFO [localhost-startStop-1] org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.useContextualLobCreation HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
20-Oct-2015 14:00:17.705 INFO [localhost-startStop-1] org.hibernate.type.BasicTypeRegistry.register HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@43d414e2
20-Oct-2015 14:00:18.117 INFO [localhost-startStop-1] org.springframework.orm.hibernate5.HibernateTransactionManager.afterPropertiesSet Using DataSource [org.apache.commons.dbcp.BasicDataSource@4c992a74] of Hibernate SessionFactory for HibernateTransactionManager
20-Oct-2015 14:00:18.130 INFO [localhost-startStop-1] org.springframework.security.web.DefaultSecurityFilterChain.<init> Creating filter chain: Ant [pattern='/lib/**'], []
20-Oct-2015 14:00:18.132 INFO [localhost-startStop-1] org.springframework.security.web.DefaultSecurityFilterChain.<init> Creating filter chain: Ant [pattern='/plugins/**'], []
20-Oct-2015 14:00:18.133 INFO [localhost-startStop-1] org.springframework.security.web.DefaultSecurityFilterChain.<init> Creating filter chain: Ant [pattern='/dist/**'], []
20-Oct-2015 14:00:18.134 INFO [localhost-startStop-1] org.springframework.security.web.DefaultSecurityFilterChain.<init> Creating filter chain: Ant [pattern='/bootstrap/**'], []
20-Oct-2015 14:00:18.135 INFO [localhost-startStop-1] org.springframework.security.web.DefaultSecurityFilterChain.<init> Creating filter chain: Ant [pattern='/css/**'], []
20-Oct-2015 14:00:18.136 INFO [localhost-startStop-1] org.springframework.security.web.DefaultSecurityFilterChain.<init> Creating filter chain: Ant [pattern='/fonts/**'], []
20-Oct-2015 14:00:18.137 INFO [localhost-startStop-1] org.springframework.security.web.DefaultSecurityFilterChain.<init> Creating filter chain: Ant [pattern='/login*'], []
20-Oct-2015 14:00:18.270 INFO [localhost-startStop-1] org.springframework.security.web.DefaultSecurityFilterChain.<init> Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.SecurityContextPersistenceFilter@4a5281b8, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@42066dde, org.springframework.security.web.header.HeaderWriterFilter@7fda7a84, org.springframework.security.web.authentication.logout.LogoutFilter@67125593, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@39134788, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@488ab5e9, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@6428f826, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@116387fd, org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter@32efbd5e, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@2f576317, org.springframework.security.web.session.SessionManagementFilter@c9d5713, org.springframework.security.web.access.ExceptionTranslationFilter@14c7512, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@4e063d28]
20-Oct-2015 14:00:18.277 INFO [localhost-startStop-1] org.springframework.security.config.http.DefaultFilterChainValidator.checkLoginPageIsntProtected Checking whether login URL '/login.do' is accessible with your configuration
20-Oct-2015 14:00:18.297 INFO [localhost-startStop-1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization completed in 1329 ms
20-Oct-2015 14:00:18.320 INFO [localhost-startStop-1] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'AccServlet': initialization started
20-Oct-2015 14:00:18.322 INFO [localhost-startStop-1] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing WebApplicationContext for namespace 'AccServlet-servlet': startup date [Tue Oct 20 14:00:18 CEST 2015]; parent: Root WebApplicationContext
20-Oct-2015 14:00:18.322 INFO [localhost-startStop-1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/AccServlet-servlet.xml]
20-Oct-2015 14:00:18.369 INFO [localhost-startStop-1] org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping.registerHandler Mapped URL path [/index.do] onto handler 'jspController'
20-Oct-2015 14:00:18.369 INFO [localhost-startStop-1] org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping.registerHandler Mapped URL path [/login.do] onto handler 'jspController'
20-Oct-2015 14:00:18.517 INFO [localhost-startStop-1] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'AccServlet': initialization completed in 197 ms
20-Oct-2015 14:00:18.517 INFO [localhost-startStop-1] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'RestServlet': initialization started
20-Oct-2015 14:00:18.518 INFO [localhost-startStop-1] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing WebApplicationContext for namespace 'RestServlet-servlet': startup date [Tue Oct 20 14:00:18 CEST 2015]; parent: Root WebApplicationContext
20-Oct-2015 14:00:18.518 INFO [localhost-startStop-1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/RestServlet-servlet.xml]
20-Oct-2015 14:00:18.539 INFO [localhost-startStop-1] org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping.registerHandler Mapped URL path [/rest/user] onto handler 'restService'
20-Oct-2015 14:00:18.539 INFO [localhost-startStop-1] org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping.registerHandler Mapped URL path [/rest/user.*] onto handler 'restService'
20-Oct-2015 14:00:18.539 INFO [localhost-startStop-1] org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping.registerHandler Mapped URL path [/rest/user/] onto handler 'restService'
20-Oct-2015 14:00:18.545 INFO [localhost-startStop-1] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'RestServlet': initialization completed in 28 ms
20-Oct-2015 14:00:18.552 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /home/googie/projects/tomcat/webapps/acc.war has finished in 2,338 ms
20-Oct-2015 14:00:18.552 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /home/googie/projects/tomcat/webapps/manager
20-Oct-2015 14:00:18.569 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /home/googie/projects/tomcat/webapps/manager has finished in 17 ms
20-Oct-2015 14:00:18.571 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
20-Oct-2015 14:00:18.578 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
20-Oct-2015 14:00:18.579 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 2394 ms
20-Oct-2015 14:00:37.639 INFO [http-nio-8080-exec-8] org.hibernate.hql.internal.QueryTranslatorFactoryInitiator.initiateService HHH000397: Using ASTQueryTranslatorFactory
20-Oct-2015 14:00:50.965 WARNING [http-nio-8080-exec-6] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/acc/rest/user] in DispatcherServlet with name 'RestServlet'
请注意,日志中的最后一行来 self 对其余服务的 GET 请求尝试。
最佳答案
发现问题。事实证明,两个 *-servlet.xml 上下文文件都应该有 <mvc:annotation-driven />
声明以使 Controller 正常工作。没有它,servlet 可以工作,但映射处理不正确。
关于java - 两个 servlet 中的 Spring、MVC 和 REST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33222838/
我有一个我想暂时存储的对象。该对象现在在 Controller 中, Controller 将生成一个 View 。 AJAX 请求从 View 发送到下一个 Controller 。那一刻我需要先前
从MVC 2开始,我们可以轻松创建区域。现在,我的问题与嵌套区域(区域内部的区域)有关。 选择我的“father”区域文件夹,右键单击> Add> NO选项以获取new Area。 是否有可能以其他方
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
我已经尝试了一些谷歌搜索和堆栈流搜索,但事实证明这比我想象的要难找到。我需要为我们的商店迁移到 ASP.NET MVC 2 的管理提供理由。最大的帮助将是任何企业级站点或使用 ASP.NET MVC
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 6 年前。 Improv
我有一些常见的网页,它们将出现在多个 MVC 应用程序中。对于这些页面,我想在不同的 MVC 网站之间重用相同的源代码( Controller + View )。这样做的最佳方法是什么? ASP.NE
我正在使用 Spring MVC 来构建我的应用程序。 当用户在浏览器中运行应用程序时,我想显示一个默认的 jsp。我不想用 web.xml 中的标记。 我想我可以用 我已经创建了一个文件夹并添
我可能在这里分析过度了,但是根据我对 MVC 的阅读,似乎有很多关于如何做事情的观点。 是否有一个“最佳实践”网站或文档来定义 MVC 各个部分的职责? 请记住,我使用 EF/Repository&U
当杰里米和查德 posted about their FubuMvc project ,他们提到的差异化因素之一是他们的“雷霆穹顶校长”: The “Thunderdome Principle” –
我正在为 Spring MVC 应用程序实现缓存清除系统。 为了让这个系统正常工作,我必须从给定的 url 中删除“缓存破坏代码”。假设我生成的缓存破坏代码是“123”,我有一个 .css url:/
在调试 ASP.NET MVC 源时,我发现使用了“MVC-ControllerTypeCache.xml” 文件。但我无法理解这个文件的用途。我的意思是这个文件存储在哪里?asp.net MVc 如
我刚刚在我的本地机器上安装了 Visual Studio 11 和 MVC 4 beta。但是,每当我打开一个 MVC 3 项目(我想保留为 MVC 3)时,所有引用都已更新为版本 4 DLL。当然它
我有一个 MVC 3 应用程序,它具有一些核心功能(最重要的是自动化),但主要用作不同区域或模块的门户。我想将它组织到不同的模块中,只需稍作更改也可以部署为他们自己的网站。 该项目由论坛、博客引擎、用
我有自己的服务器,正在考虑将我的一个解决方案升级到 ASP.NET MVC 4,然后再升级其余的 (3+)。 作为其中的一部分,我下载了 the standalone installer对于 ASP.
构图 我有一个 MVC 项目,其中包含 C# 类,这些类最终通过 ajax 等进行序列化和使用。我使用 TypeLite 生成这些 C# 类的定义( here 讨论了 TypeLite 的替代方案),
我正在尝试了解现代 Web 应用程序架构。在 ASP.NET MVC 中,所有业务逻辑类都在 Model 中,Controller 接受并引导用户请求。如果我使用它,是否可以使用本身是 MVC 架构但
我有一个带有 OWIN 的 WebAPI 2 应用程序。现在我正在尝试向所有内容添加一个 MVC 5 Controller ,但没有找到我的 MVC 路由。我收到以下错误: No HTTP resou
在 MVC 3 中,他们添加了我一直在使用的依赖解析器。在回答某人对您发表评论的问题时,您应该使用 Ninject MVC 3 插件。 所以我的问题是为什么要使用它而不是内置的?如果这是要走的路,你如
我是 ASP.NET MVC 的新手,我正在寻找最不痛苦的方法来设置全局错误处理、日志记录和报告(通过电子邮件)。仅供引用,我的 ASP.NET MVC 应用程序在 Azure 中作为 Web 角色托
何时使用 MVC View 页面和 MVC View 内容页面?它们有什么区别? 最佳答案 **MVC View Page 用于创建页面,MVC VewP Content Page 用于创建页面并指定
我是一名优秀的程序员,十分优秀!