- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 spring 的新手,我在 Spring 应用程序(基于 Java 的配置)中遇到了这个问题。
我的应用程序无法定位静态资源(css 文件、js 等)我尝试了不同的方法,但这个问题仍然存在。
我的 WebAppConfig.java 文件中有如下内容:
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan("com.x.apimanager")
@PropertySource("classpath:application.properties")
@EnableJpaRepositories("com.x.apimanager.repository")
public class WebAppConfig extends WebMvcConfigurerAdapter {
// Other codes here that is not shown.
@Bean
public UrlBasedViewResolver setupViewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setPrefix("/WEB-INF/pages/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
return resolver;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}
我的目录结构是这样的(图片可以在下面的链接中看到): http://pbrd.co/1EAR1II
我的 Spring Security Config 文件看起来像这样。我添加了一个拦截器,允许对特定文件夹的请求通过。
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
//Implementation not shown
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**");
}
}
这是在 jsp 页面/ View 上发生此问题时 firebug 显示的内容。
"NetworkError: 404 Not Found - http://localhost:9999/apimanager/resources/libs/bootstrap-3.3.1/css/navbar.css"
navbar.css
我的 jsp 页面包含以下内容:
<c:set var="url">${pageContext.request.requestURL}</c:set>
<base href="${fn:substring(url, 0, fn:length(url) - fn:length(pageContext.request.requestURI))}${pageContext.request.contextPath}/" />
<link href="resources/libs/bootstrap-3.3.1/css/navbar.css" rel="stylesheet">
我的日志显示如下:
2015-01-22 12:07:39 DEBUG SecurityContextPersistenceFilter:97 - SecurityContextHolder now cleared, as request processing completed
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 1 of 14 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 2 of 14 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2015-01-22 12:07:40 DEBUG HttpSessionSecurityContextRepository:171 - Obtained a valid SecurityContext from SPRING_SECURITY_CONTEXT: 'org.springframework.security.core.context.SecurityContextImpl@e18bbb85: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@e18bbb85: Principal: org.springframework.security.core.userdetails.User@a5979349: Username: x; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@12afc: RemoteIpAddress: 127.0.0.1; SessionId: 0102DF1734E5DCC343FF4C767FE3AD17; Granted Authorities: ROLE_USER'
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 3 of 14 in additional filter chain; firing Filter: 'HeaderWriterFilter'
2015-01-22 12:07:40 DEBUG HstsHeaderWriter:129 - Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@528199b
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 4 of 14 in additional filter chain; firing Filter: 'CsrfFilter'
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 5 of 14 in additional filter chain; firing Filter: 'LogoutFilter'
2015-01-22 12:07:40 DEBUG AntPathRequestMatcher:127 - Request 'GET /resources/libs/bootstrap-3.3.1/css/navbar.css' doesn't match 'POST /logout
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 6 of 14 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
2015-01-22 12:07:40 DEBUG AntPathRequestMatcher:127 - Request 'GET /resources/libs/bootstrap-3.3.1/css/navbar.css' doesn't match 'POST /login
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 7 of 14 in additional filter chain; firing Filter: 'DefaultLoginPageGeneratingFilter'
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 8 of 14 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 9 of 14 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 10 of 14 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 11 of 14 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
2015-01-22 12:07:40 DEBUG AnonymousAuthenticationFilter:107 - SecurityContextHolder not populated with anonymous token, as it already contained: 'org.springframework.security.authentication.UsernamePasswordAuthenticationToken@e18bbb85: Principal: org.springframework.security.core.userdetails.User@a5979349: Username: x; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@12afc: RemoteIpAddress: 127.0.0.1; SessionId: 0102DF1734E5DCC343FF4C767FE3AD17; Granted Authorities: ROLE_USER'
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 12 of 14 in additional filter chain; firing Filter: 'SessionManagementFilter'
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 13 of 14 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
2015-01-22 12:07:40 DEBUG FilterChainProxy:337 - /resources/libs/bootstrap-3.3.1/css/navbar.css at position 14 of 14 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
2015-01-22 12:07:40 DEBUG FilterSecurityInterceptor:194 - Secure object: FilterInvocation: URL: /resources/libs/bootstrap-3.3.1/css/navbar.css; Attributes: [authenticated]
2015-01-22 12:07:40 DEBUG FilterSecurityInterceptor:310 - Previously Authenticated: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@e18bbb85: Principal: org.springframework.security.core.userdetails.User@a5979349: Username: x; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@12afc: RemoteIpAddress: 127.0.0.1; SessionId: 0102DF1734E5DCC343FF4C767FE3AD17; Granted Authorities: ROLE_USER
2015-01-22 12:07:40 DEBUG AffirmativeBased:65 - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@49950c0d, returned: 1
2015-01-22 12:07:40 DEBUG FilterSecurityInterceptor:215 - Authorization successful
2015-01-22 12:07:40 DEBUG FilterSecurityInterceptor:227 - RunAsManager did not change Authentication object
2015-01-22 12:07:40 DEBUG FilterChainProxy:323 - /resources/libs/bootstrap-3.3.1/css/navbar.css reached end of additional filter chain; proceeding with original chain
2015-01-22 12:07:40 DEBUG DispatcherServlet:823 - DispatcherServlet with name 'dispatcher' processing GET request for [/apimanager/resources/libs/bootstrap-3.3.1/css/navbar.css]
2015-01-22 12:07:40 DEBUG RequestMappingHandlerMapping:226 - Looking up handler method for path /resources/libs/bootstrap-3.3.1/css/navbar.css
2015-01-22 12:07:40 DEBUG RequestMappingHandlerMapping:236 - Did not find handler method for [/resources/libs/bootstrap-3.3.1/css/navbar.css]
2015-01-22 12:07:40 WARN PageNotFound:1108 - No mapping found for HTTP request with URI [/apimanager/resources/libs/bootstrap-3.3.1/css/navbar.css] in DispatcherServlet with name 'dispatcher'
2015-01-22 12:07:40 DEBUG DispatcherServlet:966 - Successfully completed request
2015-01-22 12:07:40 DEBUG ExceptionTranslationFilter:115 - Chain processed normally
我将不胜感激这个问题的解决方案。非常感谢您回答我的问题。
最佳答案
我希望您缺少的是应用程序上下文路径。
试试这个
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/css/navbar.css" />
关于css - JSP找不到css文件(基于java的webconfig),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28110912/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!