Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 服务静态页面&;春季休憩服务_Java_Spring_Spring Mvc - Fatal编程技术网

Java 服务静态页面&;春季休憩服务

Java 服务静态页面&;春季休憩服务,java,spring,spring-mvc,Java,Spring,Spring Mvc,我开发了一个Spring应用程序,它为Spring MVC REST服务提供服务。现在我想在Spring应用程序的webapp目录中实现Angularjs。问题是我不知道如何正确配置它 我想要达到的目标: /api/…=通过SpringMVC提供REST服务的URL,如localhost:8080/api/user/1 /…=包含静态html页面的URL,如localhost:8080/index.html 我还希望默认情况下加载index.html 目前,我正在使用以下配置,它可以正常工作

我开发了一个Spring应用程序,它为Spring MVC REST服务提供服务。现在我想在Spring应用程序的webapp目录中实现Angularjs。问题是我不知道如何正确配置它

我想要达到的目标:

  • /api/…=通过SpringMVC提供REST服务的URL,如localhost:8080/api/user/1
  • /…=包含静态html页面的URL,如localhost:8080/index.html
我还希望默认情况下加载index.html

目前,我正在使用以下配置,它可以正常工作,但默认情况下不会加载index.html。但我不知道这是否真的是在Spring容器中配置静态页面的方式:

web.xml

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>dispatchOptionsRequest</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<context:property-placeholder properties-ref="deployProperties" />

<!-- Activates various annotations to be detected in bean classes -->
<context:annotation-config />

<!-- Scans the classpath for annotated components that will be auto-registered as Spring beans.
For example @Controller and @Service. Make sure to set the correct base-package -->
<context:component-scan base-package="com.eerra" />

<!-- Configures the annotation-driven Spring MVC Controller programming model.
Note that, with Spring 3.0, this tag works in Servlet MVC only! -->
<mvc:annotation-driven/>

<!-- Tell Spring what to treat as resources -->
<mvc:resources mapping="/" location="/resources/ang2/app/"/>
<!-- Setup urlrewrite filter -->
<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    <init-param>
        <param-name>logLevel</param-name>
        <param-value>WARN</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Spring related section -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>dispatchOptionsRequest</param-name>
    <param-value>true</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>
<!-- Use urlrewritefilter to redirect / requests to angularjs directory -->
<urlrewrite default-match-type="wildcard">
<rule>
    <!-- exclude everything in /api/** directory -->
    <condition type="request-uri" operator="notequal">/api/**</condition>
    <!-- everything else from / is redirected to the angularjs directory -->
    <from>/**</from>
    <to>/resources/ang2/app/$1</to>
</rule>
</urlrewrite>

org.springframework.web.context.ContextLoaderListener
春天
org.springframework.web.servlet.DispatcherServlet
DispatchOptions请求
真的
春天
/
applicationContext.xml

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>dispatchOptionsRequest</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<context:property-placeholder properties-ref="deployProperties" />

<!-- Activates various annotations to be detected in bean classes -->
<context:annotation-config />

<!-- Scans the classpath for annotated components that will be auto-registered as Spring beans.
For example @Controller and @Service. Make sure to set the correct base-package -->
<context:component-scan base-package="com.eerra" />

<!-- Configures the annotation-driven Spring MVC Controller programming model.
Note that, with Spring 3.0, this tag works in Servlet MVC only! -->
<mvc:annotation-driven/>

<!-- Tell Spring what to treat as resources -->
<mvc:resources mapping="/" location="/resources/ang2/app/"/>
<!-- Setup urlrewrite filter -->
<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    <init-param>
        <param-name>logLevel</param-name>
        <param-value>WARN</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Spring related section -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>dispatchOptionsRequest</param-name>
    <param-value>true</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>
<!-- Use urlrewritefilter to redirect / requests to angularjs directory -->
<urlrewrite default-match-type="wildcard">
<rule>
    <!-- exclude everything in /api/** directory -->
    <condition type="request-uri" operator="notequal">/api/**</condition>
    <!-- everything else from / is redirected to the angularjs directory -->
    <from>/**</from>
    <to>/resources/ang2/app/$1</to>
</rule>
</urlrewrite>

在当前配置下,一切正常,但当我尝试将浏览器指向localhost:8080/时,会出现404 not found,而不是加载index.html文件。当我尝试使用localhost:8080/index.html时,一切都正常

有人能告诉我如何配置这样的设置吗

下面您可以看到我的debug.log。这里的问题似乎如下:

未找到[]的处理程序方法。

所以我猜DispatcherServlet正在尝试将路径映射到控制器。但我不知道怎样才能避免这种情况

21:55:04.896 [qtp581501261-25] DEBUG org.eclipse.jetty.http.HttpParser - filled 314/314
21:55:04.897 [qtp581501261-25 - /] DEBUG org.eclipse.jetty.server.Server - REQUEST / on AsyncHttpConnection@f908897,g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-5,l=9,c=0},r=1
21:55:04.897 [qtp581501261-25 - /] DEBUG o.e.j.server.handler.ContextHandler - scope null||/ @ o.m.j.p.JettyWebAppContext{/,file:/C:/Users/charms/Documents/Intellij%20Projects/cardkeeper/src/main/webapp/},file:/C:/Users/charms/Documents/Intellij%20Projects/cardkeeper/src/main/webapp/
21:55:04.897 [qtp581501261-25 - /] DEBUG o.e.j.server.handler.ContextHandler - context=||/ @ o.m.j.p.JettyWebAppContext{/,file:/C:/Users/charms/Documents/Intellij%20Projects/cardkeeper/src/main/webapp/},file:/C:/Users/charms/Documents/Intellij%20Projects/cardkeeper/src/main/webapp/
21:55:04.897 [qtp581501261-25 - /] DEBUG org.eclipse.jetty.server.session - sessionManager=org.eclipse.jetty.server.session.HashSessionManager@70799896
21:55:04.897 [qtp581501261-25 - /] DEBUG org.eclipse.jetty.server.session - session=null
21:55:04.897 [qtp581501261-25 - /] DEBUG o.e.jetty.servlet.ServletHandler - servlet |/|null -> spring
21:55:04.897 [qtp581501261-25 - /] DEBUG o.e.jetty.servlet.ServletHandler - chain=springSecurityFilterChain->spring
21:55:04.897 [qtp581501261-25 - /] DEBUG o.e.jetty.servlet.ServletHandler - call filter springSecurityFilterChain
21:55:04.897 [qtp581501261-25 - /] DEBUG o.s.s.web.util.AntPathRequestMatcher - Checking match of request : '/'; against '/favicon.ico*'
21:55:04.897 [qtp581501261-25 - /] DEBUG o.s.s.web.util.AntPathRequestMatcher - Checking match of request : '/'; against '/resources/**'
21:55:04.897 [qtp581501261-25 - /] DEBUG o.s.security.web.FilterChainProxy - / at position 1 of 9 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
21:55:04.898 [qtp581501261-25 - /] DEBUG o.s.security.web.FilterChainProxy - / at position 2 of 9 in additional filter chain; firing Filter: 'LogoutFilter'
21:55:04.898 [qtp581501261-25 - /] DEBUG o.s.security.web.FilterChainProxy - / at position 3 of 9 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
21:55:04.898 [qtp581501261-25 - /] DEBUG o.s.security.web.FilterChainProxy - / at position 4 of 9 in additional filter chain; firing Filter: 'DefaultLoginPageGeneratingFilter'
21:55:04.898 [qtp581501261-25 - /] DEBUG o.s.security.web.FilterChainProxy - / at position 5 of 9 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
21:55:04.898 [qtp581501261-25 - /] DEBUG o.s.security.web.FilterChainProxy - / at position 6 of 9 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
21:55:04.898 [qtp581501261-25 - /] DEBUG o.s.security.web.FilterChainProxy - / at position 7 of 9 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
21:55:04.898 [qtp581501261-25 - /] DEBUG o.s.s.w.a.AnonymousAuthenticationFilter - Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken@9055c2bc: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS'
21:55:04.898 [qtp581501261-25 - /] DEBUG o.s.security.web.FilterChainProxy - / at position 8 of 9 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
21:55:04.898 [qtp581501261-25 - /] DEBUG o.s.security.web.FilterChainProxy - / at position 9 of 9 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
21:55:04.898 [qtp581501261-25 - /] DEBUG o.s.s.web.util.AntPathRequestMatcher - Checking match of request : '/'; against '/api/**'
21:55:04.899 [qtp581501261-25 - /] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor - Public object - authentication not attempted
21:55:04.899 [qtp581501261-25 - /] TRACE o.s.w.c.s.XmlWebApplicationContext - Publishing event in Root WebApplicationContext: org.springframework.security.access.event.PublicInvocationEvent[source=FilterInvocation: URL: /]
21:55:04.899 [qtp581501261-25 - /] DEBUG o.s.security.web.FilterChainProxy - / reached end of additional filter chain; proceeding with original chain
21:55:04.899 [qtp581501261-25 - /] DEBUG o.e.jetty.servlet.ServletHandler - call servlet spring
21:55:04.899 [qtp581501261-25 - /] TRACE o.s.web.servlet.DispatcherServlet - Bound request context to thread: SecurityContextHolderAwareRequestWrapper[ FirewalledRequest[ (GET /)@604241542 org.eclipse.jetty.server.Request@2403fe86]]
21:55:04.899 [qtp581501261-25 - /] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'spring' processing GET request for [/]
21:55:04.899 [qtp581501261-25 - /] TRACE o.s.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@12440d38] in DispatcherServlet with name 'spring'
21:55:04.899 [qtp581501261-25 - /] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /
21:55:04.912 [qtp581501261-25 - /] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/]
21:55:04.912 [qtp581501261-25 - /] TRACE o.s.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@c518734] in DispatcherServlet with name 'spring'
21:55:04.912 [qtp581501261-25 - /] TRACE o.s.w.s.h.BeanNameUrlHandlerMapping - No handler mapping found for [/]
21:55:04.912 [qtp581501261-25 - /] TRACE o.s.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@3c836d3d] in DispatcherServlet with name 'spring'
21:55:04.912 [qtp581501261-25 - /] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns for request [/] are [/**]
21:55:04.912 [qtp581501261-25 - /] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - URI Template variables for request [/] are {}
21:55:04.912 [qtp581501261-25 - /] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Mapping [/] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@6abe6713] and 1 interceptor
21:55:04.912 [qtp581501261-25 - /] TRACE o.s.web.servlet.DispatcherServlet - Testing handler adapter [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter@7a614724]
21:55:04.912 [qtp581501261-25 - /] TRACE o.s.web.servlet.DispatcherServlet - Testing handler adapter [org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter@885cb41]
21:55:04.912 [qtp581501261-25 - /] DEBUG o.s.web.servlet.DispatcherServlet - Last-Modified value for [/] is: -1
21:55:04.912 [qtp581501261-25 - /] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Ignoring invalid resource path []
21:55:04.913 [qtp581501261-25 - /] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - No matching resource found - returning 404
21:55:04.913 [qtp581501261-25 - /] DEBUG o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'spring': assuming HandlerAdapter completed request handling
21:55:04.913 [qtp581501261-25 - /] TRACE o.s.web.servlet.DispatcherServlet - Cleared thread-bound request context: SecurityContextHolderAwareRequestWrapper[ FirewalledRequest[ [GET /]@604241542 org.eclipse.jetty.server.Request@2403fe86]]
21:55:04.914 [qtp581501261-25 - /] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
21:55:04.914 [qtp581501261-25 - /] TRACE o.s.w.c.s.XmlWebApplicationContext - Publishing event in WebApplicationContext for namespace 'spring-servlet': ServletRequestHandledEvent: url=[/]; client=[0:0:0:0:0:0:0:1]; method=[GET]; servlet=[spring]; session=[null]; user=[null]; time=[15ms]; status=[OK]
21:55:04.914 [qtp581501261-25 - /] TRACE o.s.w.c.s.XmlWebApplicationContext - Publishing event in Root WebApplicationContext: ServletRequestHandledEvent: url=[/]; client=[0:0:0:0:0:0:0:1]; method=[GET]; servlet=[spring]; session=[null]; user=[null]; time=[15ms]; status=[OK]
21:55:04.914 [qtp581501261-25 - /] DEBUG o.s.s.w.a.ExceptionTranslationFilter - Chain processed normally
21:55:04.914 [qtp581501261-25 - /] DEBUG o.s.s.w.c.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
21:55:04.914 [qtp581501261-25 - /] DEBUG org.eclipse.jetty.server.Server - RESPONSE /  404 handled=true
21:55:04.915 [qtp581501261-25] DEBUG o.e.jetty.server.AsyncHttpConnection - Enabled read interest SCEP@7cee85c5{l(/0:0:0:0:0:0:0:1:51001)<->r(/0:0:0:0:0:0:0:1:8080),d=true,open=true,ishut=false,oshut=false,rb=false,wb=false,w=true,i=0r}-{AsyncHttpConnection@f908897,g=HttpGenerator{s=4,h=0,b=0,c=-1},p=HttpParser{s=0,l=9,c=0},r=1}
21:55:04.915 [qtp581501261-25] DEBUG org.eclipse.jetty.http.HttpParser - filled 0/0
21:55:04.896[qtp581501261-25]调试org.eclipse.jetty.http.HttpParser-填充314/314
21:55:04.897[qtp581501261-25-/]调试org.eclipse.jetty.server.server-REQUEST/onAsyncHttpConnection@f908897,g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-5,l=9,c=0},r=1
21:55:04.897[qtp581501261-25-/]调试o.e.j.server.handler.ContextHandler-scope null | |/@o.m.j.p.JettyWebAppContext{/,文件:/C:/Users/charms/Documents/Intellij%20Projects/cardkeeper/src/main/webapp/,文件:/C:/Users/charms/Documents/Intellij%20Projects/cardkeeper/src/main/webapp/
21:55:04.897[qtp581501261-25-/]调试o.e.j.server.handler.ContextHandler-context=| |/@o.m.j.p.JettyWebAppContext{/,文件:/C:/Users/charms/Documents/Intellij%20Projects/cardkeeper/src/main/webapp/,文件:/C:/Users/charms/Documents/Intellij%20Projects/cardkeeper/src/main/webapp/
21:55:04.897[qtp581501261-25-/]调试org.eclipse.jetty.server.session-sessionManager=org.eclipse.jetty.server.session。HashSessionManager@70799896
21:55:04.897[qtp581501261-25-/]DEBUG org.eclipse.jetty.server.session-session=null
21:55:04.897[qtp581501261-25-/]调试o.e.jetty.servlet.ServletHandler-servlet |/| null->spring
21:55:04.897[qtp581501261-25-/]调试o.e.jetty.servlet.ServletHandler-chain=springSecurityFilterChain->spring
21:55:04.897[qtp581501261-25-/]调试o.e.jetty.servlet.ServletHandler-调用筛选器springSecurityFilterChain
21:55:04.897[qtp581501261-25-/]调试o.s.s.web.util.AntPathRequestMatcher-检查请求的匹配:'/';反对“/favicon.ico*”
21:55:04.897[qtp581501261-25-/]调试o.s.s.web.util.AntPathRequestMatcher-检查请求的匹配:'/';针对“/resources/**”
21:55:04.897[qtp581501261-25-/]调试o.s.security.web.FilterChainProxy-/位于附加过滤器链中9的位置1处;正在启动筛选器:“SecurityContextPersistenceFilter”
21:55:04.898[qtp581501261-25-/]调试o.s.security.web.FilterChainProxy-/位于附加过滤器链中9的位置2处;正在启动筛选器:“注销筛选器”
21:55:04.898[qtp581501261-25-/]调试o.s.security.web.FilterChainProxy-/位于附加过滤器链中9的第3位;正在启动筛选器:“UsernamePasswordAuthenticationFilter”
21:55:04.898[qtp581501261-25-/]调试o.s.security.web.FilterChainProxy-/位于附加过滤器链中9的第4位;正在启动筛选器:“DefaultLoginPageGeneratingFilter”
21:55:04.898[qtp581501261-25-/]调试o.s.security.web.FilterChainProxy-/位于附加过滤器链中9的第5位;触发筛选器:“基本身份验证筛选器”
21:55:04.898[qtp581501261-25-/]调试o.s.security.web.FilterChainProxy-/位于附加过滤器链中9的第6位;正在启动筛选器:“SecurityContextHolderAwareRequestFilter”
21:55:04.898[qtp581501261-25-/]调试o.s.security.web.FilterChainProxy-/位于附加过滤器链中9的第7位;正在启动筛选器:“匿名身份验证筛选器”
21:55:04.898[qtp581501261-25-/]调试o.s.s.w.a.AnonymousAuthenticationFilter-使用匿名令牌填充SecurityContextHolder:'org.springframework.security.authentication。AnonymousAuthenticationToken@9055c2bc:委托人:匿名用户;凭据:[受保护];认证:正确;详细信息:org.springframework.security.web.authentication。WebAuthenticationDetails@b364:RemoteIP地址:0:0:0:0:0:0:0:0:1;SessionId:null;授予的权限:角色\u匿名'
21:55:04.898[qtp581501261-25-/]调试o.s.security.web.FilterChainProxy-/位于附加过滤器链中9的第8位;正在启动筛选器:“ExceptionTranslationFilter”
21:55:04.898[qtp581501261-25-/]调试o.s.security.web.FilterChainProxy-/位于附加过滤器链中9/9处;触发筛选器:“筛选器安全侦听器”
21:55:04.898[qtp581501261-25-/]调试o.s.s.web.util.AntPathRequestMatcher-检查请求的匹配:'/';针对“/api/**”
21:55:04.899[qtp581501261-25-/]调试o.s.s.w.a.i.FilterSecurityInterceptor-公共对象-未尝试身份验证
21:55:04.899[qtp581501261-25-/]跟踪o.s.w.c.s.XmlWebApplicationContext-根WebApplicationContext中的发布事件:org.springframework.security.access.event.PublicInvocationEvent[source=FilterInvocation:URL://]
21:55:04.899[qtp581501261-25-/]调试o.s.security.web.FilterChainProxy-/已到达附加筛选器的末尾