WebSecurityConfigurerAdapter.class]无法打开,因为它不存在

时间:2017-12-30 20:06:10

标签: java spring intellij-idea spring-security

在构建spring app之后,我遇到了这个问题:

  .../WebSecurityConfigurerAdapter.class] cannot be opened because it does not exist at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)

我的pom.xml

<properties>
    <spring.version>4.3.0.RELEASE</spring.version>
    <springsecurity.version>4.2.3.RELEASE</springsecurity.version>
    <!--<springsecurity.version>5.0.0.RELEASE</springsecurity.version>-->
</properties>


<dependencies>


    <!--spring security web and config-->

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${springsecurity.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${springsecurity.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>${springsecurity.version}</version>
    </dependency>

SecurityConfig类:

    @Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().withUser("john").password("secret123").roles("EMPLOYEE");
        auth.inMemoryAuthentication().withUser("mary").password("secret123").roles("MANAGER");
        auth.inMemoryAuthentication().withUser("susan").password("secret123").roles("ADMIN");

    }

}

Inizializer:

public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {

}

它似乎无法在构建后找到jar文件。我尝试将它添加到IntelliJ Idea中的Project Structure中的工件中,但它没有帮助。

2 个答案:

答案 0 :(得分:0)

How to add artifact

转到项目结构 - &gt;文物 - &gt;点击绿色'+'按钮 - &gt;和所有Spring Security库?

答案 1 :(得分:0)

当前,从2018年10月开始,如果您使用的是Java 10,则将遇到最新的spring-security-config Maven依赖关系问题。解决方法是下载 spring-security-config-5.0.6.RELEASE.jar from here。将jar添加到您的Classpath中,这应该可以解决问题。