0
春のアプリケーションの静的リソース(js、cssなど)はもはや利用できない構成で戦っています。私は何が欠けているかを指摘できるでしょうか。ここにコードがあります。私のJSとCSSは次のフォルダにあります。また、春のセキュリティを有効にする前に、これらのリソースは、私がリンク春のセキュリティを有効にした後は、静的リソースはもう利用できません
<script src="resources/js/jquery.js"></script>
以下でjsのフォルダにjqueryのにアクセスしたいと、ブラウザでエラーが
である私のJSPページで
Web Pages ->
WEB-INF ->
resources ->
and here 2 folders js and css
アクセス可能だったことに注意してくださいリソースをロードできませんでした:http://localhost:8010/resources/js/js.jsサーバは404のステータスで応答しました(見つからなかった)
@Configuration
@EnableScheduling // if you want certain function running on the backend on recurrning basis like very 5 second a function call itself then you have to ensbale this. this will enable all classes defined as Service and Scheduled to be running on backend automatically. see example in com.outbottle.controllers.ScheduledTasks.java
@ComponentScan("com.outbottle, com.JavaAnatatedClass") //this will import all beans marked as @Controller, or @Repository, or @Service, or @Component in the application context
@ImportResource({"classpath:beans1.xml"}) //this will import all beans in the application context from this xml file
@EnableWebMvc
public class Config extends WebMvcConfigurerAdapter {
@Bean
public UrlBasedViewResolver setupViewResolver() {
.....
.....
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/**");
}
ここにセキュリティ構成ファイルがあります。
@Configuration
@EnableWebSecurity
//@PropertySource("classpath:jdbc.properties")
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
AuthenticationService as = new AuthenticationService();
auth.userDetailsService(as);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/home", "/REST").permitAll()
.antMatchers("/resources/**").permitAll()
.antMatchers("/admin/**").access("hasAuthority('ADMIN')") //you have to use hasAuthority because in AuthenticationService you are using GrantedAuthority object. i replaced hasRole with hasAuthority. check the detailes below in comments
.antMatchers("/db/**").access("hasAuthority('ADMIN') and hasAuthority('DBA')")
//Custom Login Form with fields and values
//.and().formLogin() //this will show default spring login page
.and().formLogin().loginPage("/login")
.usernameParameter("ssoId").passwordParameter("password") //these aret the fields on the login page for user and password
.and().csrf()
.and().exceptionHandling().accessDeniedPage("/Access_Denied");
}
通常、ブラウザは/ WEB-INFから物事を取得できません。ただし、ハンドラによって明示的に配信することはできます。私はすぐにwebappディレクトリ/ like/resources/jsに配置します。 –