我启动了Spring Boot + Angular应用程序,现在我想将整个东西部署为jar。所以我创建了Maven配置,在其中构建了角度应用程序,然后将其复制到/ target / classes / resources

但是对根(localhost:8080)的每个请求都被安全性阻止。当我禁用它时,我可以看到该页面,这意味着整个东西都已正确部署,但是以某种方式spring不允许我看到它。这是我简单的安全配置,我希望静态资源不受保护,而其他任何请求都需要身份验证:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
                .anyRequest().authenticated()
                .and().httpBasic();
    }
}

编辑:
我的问题的一个最小示例在这里:
https://gitlab.com/jnowacki/security-issue-demo

编辑2:
我尝试了这篇文章中的所有内容:
Serving static web resources in Spring Boot & Spring Security application
我在概念上做错了吗?与Spring Boot应用程序一起提供静态内容是否错误?

最佳答案

添加此其他替代:

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring()
            .antMatchers(AUTH_WHITELIST);
}

其中AUTH_WHITELIST将包含要忽略的路径。例如:
private static final String[] SWAGGER_AUTH_WHITELIST = {
        // -- swagger ui
        "/v2/api-docs",
        "/swagger-resources",
        "/swagger-resources/**",
        "/swagger-ui.html",
        "/resources/**"
};

10-08 04:52