spring - 实现spring security后无法在网页上加载bootstrap

标签 spring twitter-bootstrap

我正在使用具有 Bootstrap 依赖项的 spring boot。实现部分代码后,我无法使用 Bootstrap 加载我的网页(页面将加载但不会使用 Bootstrap )。我正在使用 spring bootstrap 依赖项。有人使用 spring boot 和 thymeleaf 有类似的结果吗?

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers().permitAll().anyRequest().authenticated().and().formLogin()
    .loginPage("/login").permitAll().and().logout().permitAll();
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
}

最佳答案

如果向 css 报告问题,我使用这样的配置

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true,prePostEnabled = true)
public class WebSecurityContext extends WebSecurityConfigurerAdapter {

...

 @Override
    protected void configure(HttpSecurity http) throws Exception {
        http....
            .and()
                .authorizeRequests()
                .antMatchers(LOG_IN_URL_PAGE,
                        LOG_OUT_URL_PAGE,
                        "/css/**",
                        "/js/**",
                        "/img/**",
                        "/**/favicon.ico",
                        "/webjars/**",
                        "/signup").permitAll()
                             .antMatchers("/**").fullyAuthenticated()
                             .anyRequest().authenticated();
     }

     ...

     }

我的 pom 中的 webjars 依赖项

<!--static assets-->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>1.11.1</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.4</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>select2</artifactId>
            <version>3.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>select2-bootstrap-css</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>angularjs</artifactId>
            <version>1.3.15</version>
        </dependency>

我在我的开源项目中使用这样的配置并为我工作

关键是你在 Spring Secuirty 说过不保护资源 url

对于 resorce url Spring boot autoconfiguration 为你工作它是 webjars 作为使用示例的动机

您可以在链接 http://www.webjars.org/ 中查看完整的可用 webjar 集

希望对你有帮助

关于spring - 实现spring security后无法在网页上加载bootstrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35902180/

相关文章:

java - 为什么@EnableWs从spring bean中删除aop代理

java - 如何正确暴露Web应用程序上传的图像?

html - 当我通过 CSS 调整大小时,为什么我的图像会缩小太多?

twitter-bootstrap - Bootstrap 3 工具提示或弹出框不起作用

javascript - super 菜单的第三级不起作用

java - 使用 spring 将 http 响应作为字符串获取

java - Spring 中基于模式的事务

java - Spring MVC + Hibernate @Transactional 异常后不回滚

javascript - 如何在html表格中使用分页

css - Twitter Bootstrap - 连续设置超过 12 列的样式?