2017-02-14 69 views
0

我正在尝试使用我的web应用程序配置Spring Security。我已经包含在我的pom.xml以下Spring MVC + STS + Maven:WebSecurity无法解析。它是从所需的.class文件间接引用的

<dependencies> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-webmvc</artifactId> 
    <version>4.3.5.RELEASE</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>log4j</groupId> 
    <artifactId>log4j</artifactId> 
    <version>1.2.17</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.springframework.data</groupId> 
    <artifactId>spring-data-jpa</artifactId> 
    <version>1.10.6.RELEASE</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>commons-dbcp</groupId> 
    <artifactId>commons-dbcp</artifactId> 
    <version>1.4</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-log4j12</artifactId> 
    <version>1.7.22</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-core</artifactId> 
    <version>5.2.6.Final</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-ehcache</artifactId> 
    <version>5.2.6.Final</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.hibernate.javax.persistence</groupId> 
    <artifactId>hibernate-jpa-2.1-api</artifactId> 
    <version>1.0.0.Final</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-orm</artifactId> 
    <version>4.3.5.RELEASE</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.hsqldb</groupId> 
    <artifactId>hsqldb</artifactId> 
    <version>2.3.4</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-test</artifactId> 
    <version>4.3.5.RELEASE</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.thymeleaf</groupId> 
    <artifactId>thymeleaf-spring4</artifactId> 
    <version>3.0.3.RELEASE</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.webjars</groupId> 
    <artifactId>bootstrap</artifactId> 
    <version>3.3.7-1</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.webjars</groupId> 
    <artifactId>jquery</artifactId> 
    <version>3.1.1-1</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.webjars</groupId> 
    <artifactId>webjars-locator</artifactId> 
    <version>0.32</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>com.fasterxml.jackson.core</groupId> 
    <artifactId>jackson-databind</artifactId> 
    <version>2.8.6</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.webjars</groupId> 
    <artifactId>font-awesome</artifactId> 
    <version>4.7.0</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>javax.validation</groupId> 
    <artifactId>validation-api</artifactId> 
    <version>1.1.0.Final</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.springframework.security</groupId> 
    <artifactId>spring-security-web</artifactId> 
    <version>4.2.1.RELEASE</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-web</artifactId> 
    <version>4.3.5.RELEASE</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.springframework.security</groupId> 
    <artifactId>spring-security-config</artifactId> 
    <version>3.2.0.RELEASE</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-core</artifactId> 
    <version>4.3.5.RELEASE</version> 
    <scope>compile</scope> 
</dependency> 

然而,当我与一个叫CustomWebSecurityConfigurer类扩展WebSecurityConfigurerAdapter,我从STS此错误:

The type org.springframework.security.config.annotation.web.builders.WebSecurity cannot be resolved. It is indirectly referenced from required .class files 

The hierarchy of the type CustomWebSecurityConfigurer is inconsistent 

The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.security.config.annotation.web.builders.WebSecurity. Fix the build path then try building this project 

我使用Spring工具套件3.8.3.RELEASE

我也试图Spring框架汜添加到我的dependecy管理作为描述但我仍然得到错误。

<dependency> 
    <groupId>org.springframework.security</groupId> 
    <artifactId>spring-security-config</artifactId> 
    <version>3.2.0.RELEASE</version> 
    <scope>compile</scope> 
</dependency> 

我CustomWebSecurityConfigurer包含任何尚未:

@Configuration 
@EnableWebSecurity 
public class CustomWebSecurityConfigurer extends WebSecurityConfigurerAdapter { 

    public CustomWebSecurityConfigurer() { 
     // TODO Auto-generated constructor stub 
    } 

} 

我得到编译时错误

这个错误,当我改变弹簧安全配置的版本以下不会出现时间。

+0

分享您的完整pom.xml – mhshimul

+0

也分享'CustomWebSecurityConfigurer'。此外,你什么时候得到这个错误;在编译时在STS或运行时? –

+0

使用所有同一版本的'spring-security'罐子。它会正常工作。 –

回答

0

这样做的唯一原因是,它是无法找到WebSecurity.class文件,但你已经添加了必需的依赖应该是存在于库中。这意味着该问题是
无论这些库不是在构建路径中
所以一定要确保这些库的构建路径上。

还是依赖(jar文件)尚未下载(这可能并非如此)。

如果没有上述问题存在,然后清理项目和maven更新它。如果这也不能工作,那么只需刷新您的STS,退出并再次启动
另一种解决方案被强制更新快照(行家)
右键单击该项目时,Maven - >更新项目[不要忘记检查力更新]。检查这张图片。 image

+0

我也试过,但它没有工作 – Paul

0

谢谢Tahir。我已经尝试过,但没有奏效。我认为它是一个maven bug,所以我做了删除〜/ .m2/repository文件夹,然后重新启动了我的STS。有效。

+0

酷,所以我的回答没有奏效:p –

相关问题