2016-08-25 45 views
0

我一直在搜索和搜索,但找不到合適的異常我得到的溶劑。我正在用java,spring mvc,hibernate & MySQL構建一個web應用程序。我使用過Spring Security,因爲只有授權的用戶才被允許使用該Web應用程序。我使用的CSS(引導),使它看起來不錯,但現在的問題是,我訪問得到下面的異常資源時:資源處理程序Spring異常:org.springframework.web.servlet.DispatcherServlet noHandlerFound

aug 25, 2016 10:41:38 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/ToolManagementSystem/admin/resources/css/alfen.css] in DispatcherServlet with name 'dispatcher' 
aug 25, 2016 10:41:38 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/ToolManagementSystem/admin/resources/img/logo.jpg] in DispatcherServlet with name 'dispatcher' 
aug 25, 2016 10:41:38 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/ToolManagementSystem/admin/resources/css/bootstrap.css] in DispatcherServlet with name 'dispatcher' 

的唯一方法(我發現至今),以防止這在我resourcehandler明確地定義每一個代碼路徑

// Grants access to resources 
@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) { 
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); 
} 

這裏是我的安全配置

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http.authorizeRequests() 
    .antMatchers("/css/**", "/js/**", "/images/**").permitAll().anyRequest().authenticated() 
    .antMatchers("/resources/**").permitAll().anyRequest().authenticated() 
    .antMatchers("/admin/**").access("hasRole('ADMIN')") 
    .antMatchers("/db/**").access("hasRole('DBA')") 
    .antMatchers("/lead/**").access("hasRole('LEAD')") 
    .antMatchers("/responsible/**").access("hasRole('RESPONSIBLE')") 
    .and().formLogin().loginPage("/login").successHandler(customSuccessHandler) 
    .usernameParameter("ssoId").passwordParameter("password") 
    .and().csrf() 
    .and().exceptionHandling().accessDeniedPage("/Access_Denied"); 
} 

乾杯,夥計們,幫了我/我指明瞭正確的方向! (我的道歉,如果這原來重複的問題)

解決方案,我已經試過了是:

// Grants access to resources 
@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) {  
registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/"); 
    registry.addResourceHandler("/**/resources/**".addResourceLocations("/resources/)" 
    } 

和幾個變化的安全CONFIGS的方式,但是我願意接受所有的想法/建議!

回答

0

所以,在我的代碼後多了一個鬼混。我找到了我的問題的答案,結果非常簡單。

我的鏈接資源,在JSP的之前是這樣的:

<link href="resources/css/bootstrap.css" rel="stylesheet" media="screen" /> 
<link href="resources/css/alfen.css" rel="stylesheet" media="screen" /> 

至極是不是它應該是。這是什麼使所有差異:

<link href="${pageContext.request.contextPath}/resources/css/bootstrap.css" rel="stylesheet" media="screen" /> 
<link href="${pageContext.request.contextPath}/resources/css/alfen.css" rel="stylesheet" media="screen" /> 

現在它的工作完美。所以爲了完成,我想把這張貼作爲可能的解決方案之一,當你可能遇到同樣的問題!

相關問題