Spring MIME类型(' text / html')不可执行,并且启用了严格的MIME类型检查

时间:2017-01-22 06:19:38

标签: spring

我写网站,一切正常,但当我添加下一页时,所有网站都倒下了。 我收到了这条消息:

localhost/:1 Refused to execute script from 'http://localhost:8080/js/jquery-1.12.3.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
localhost/:1 Refused to execute script from 'http://localhost:8080/js/modalWindow.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
localhost/:1 Refused to execute script from 'http://localhost:8080/js/jquery-ui.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
localhost/:1 Refused to execute script from 'http://localhost:8080/js/jquery.validate.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
localhost/:1 Refused to execute script from 'http://localhost:8080/css/1/js-image-slider.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
localhost/:1 Refused to execute script from 'http://localhost:8080/css/bootstrap/js/bootstrap.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

我尝试添加另一个页面,但它是一样的。 更重要的是,我无法看到我的所有图片,网站在目录"静态"中找不到路径(backgrounds / phone32.png)。 我不明白我在哪里可以找到这个问题的解决方案。 这个主页:

@Controller
public class MainController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ModelAndView viewMainPage() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("index");
        return modelAndView;
    }
}

此代码另一页:

@Controller
public class ClothFabricController {

    @Autowired
    private ClothFabricService service;

    @RequestMapping(name = "/cloth", method = {RequestMethod.GET})
    public ModelAndView seeCloth(){
        ModelAndView modelAndView = new ModelAndView();
        List<ClothFabricDTO> dtos = service.seeAllCloth();
        modelAndView.addObject("allCloth", dtos);
        modelAndView.setViewName("allFabric/clothFabric");
        return modelAndView;
    }
}

SpringSecurity:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    private UserDetailsService userDetailsService;

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private DataSource dataSource;

    @Override
    protected void configure(final HttpSecurity httpSecurity) throws Exception {
        httpSecurity
                .authorizeRequests()

                .antMatchers("/css/**", "/js/**", "/image/**")
                .permitAll()
                .antMatchers("/backgrounds/**")
                .permitAll()
                .antMatchers("/registrationPage")
                .permitAll()
                .antMatchers("/")
                .permitAll()
                .antMatchers("/testo")
                .permitAll()
                .antMatchers("/addRadio")
                .permitAll()
                .antMatchers("/cloth")
                .permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .defaultSuccessUrl("/")
                .passwordParameter("password")
                .permitAll()
                //благодаря этой строчке при logout кидает на индекс, если ее удрать будет кидать на logout
                .and().logout().logoutSuccessUrl("/")
                .and()
                .httpBasic()
                .and()
                .csrf().disable();

        httpSecurity.rememberMe().rememberMeParameter("remember-me")
                .rememberMeCookieName("my-remember-me")
                .tokenRepository(persistentTokenRepository()).tokenValiditySeconds(86400000);


        httpSecurity.addFilterBefore(authenticationFilter(), UsernamePasswordAuthenticationFilter.class);
    }
    //    JDBC Authentication
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        //receive login(userDetailsService) and password (passwordEncoder) from DB
        auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new MyPasswordEncoder();
    }


    public IsAccountNonExpiredFilter authenticationFilter() throws Exception {
        IsAccountNonExpiredFilter authFilter = new IsAccountNonExpiredFilter();
        authFilter.setRequiresAuthenticationRequestMatcher(new AntPathRequestMatcher("/login","POST"));

        authFilter.setAuthenticationManager(super.authenticationManager());
        authFilter.setAuthenticationSuccessHandler(new SimpleUrlAuthenticationSuccessHandler("/"));
        authFilter.setAuthenticationFailureHandler(new SimpleUrlAuthenticationFailureHandler("/login?error"));
        authFilter.setUsernameParameter("username");
        authFilter.setPasswordParameter("password");
        authFilter.setUserRepository(userRepository);
        return authFilter;
    }

    @Bean
    public PersistentTokenRepository persistentTokenRepository() {
        JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
        tokenRepository.setDataSource(dataSource);
        return tokenRepository;
    }

}

0 个答案:

没有答案