我有一个带有百里香的弹簧启动应用程序,问题已经在这里提出http://forum.thymeleaf.org/CSS-and-JS-Not-Resolving-td4028878.html。由于某种原因,应用程序今天工作正常。我正在使用spring-boot开箱即用的配置。
对于我的所有脚本和样式,thymyleaf尝试将其解析为一个奇怪的模板。例如,当我尝试获取jquery
时出现错误{"timestamp":1454200386383,"status":500,"error":"Internal Server Error","exception":"org.thymeleaf.exceptions.TemplateInputException","message":"Error resolving template \"scripts/jquery.min\", template might not exist or might not be accessible by any of the configured Template Resolvers","path":"/scripts/jquery.min.js"}
这是我的配置
@Configuration
@EnableWebMvc
@ComponentScan("com.")
public class MvcWebConfig extends WebMvcConfigurerAdapter {
@Autowired
MessageRepository repository;
static final Logger logger = LoggerFactory.getLogger(MvcWebConfig.class);
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/static/", "classpath:/static/images/", "classpath:/static/css/"};
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
}
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName("language");
return localeChangeInterceptor;
}
@Bean(name = "localeResolver")
public CookieLocaleResolver localeResolver() {
CookieLocaleResolver localeResolver = new CookieLocaleResolver();
Locale defaultLocale = new Locale("en");
localeResolver.setDefaultLocale(defaultLocale);
return localeResolver;
}
@Bean
public DatabaseDrivenMessageSource messageSource() {
DatabaseDrivenMessageSource messageSource = new DatabaseDrivenMessageSource();
messageSource.setRepository(repository);
messageSource.reload();
return messageSource;
}
这是我的安全配置
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
CustomUserDetailsService userService;
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/scripts/**", "/css/**", "/images/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/index", "/login","/career", "/contact", "/error").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/")
.permitAll();
http.csrf()
.csrfTokenRepository(csrfTokenRepository());
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userService);
}
private CsrfTokenRepository csrfTokenRepository() {
HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository();
repository.setSessionAttributeName("_csrf");
return repository;
}
}
提前致谢
答案 0 :(得分:0)
我在其中一个请求映射中输入了一个拼写错误如下
.slide {
width:1280px;
height:400px;
background-image:url(background.jpg);
-webkit-background-size: cover!important;
-moz-background-size: cover!important;
-o-background-size: cover!important;
background-size: cover!important;
background-position:center center;
background-repeat:no-repeat;
}
应该是
@RequestMapping(name = "/url", method = RequestMethod.GET)
我不知道幕后发生了什么更多细节,但错误信息也没有提供有关错误根本原因的信息。