【问题标题】:Spring annotations don't work after adding Spring Security libraries (Maven)添加 Spring Security 库 (Maven) 后,Spring 注释不起作用
【发布时间】:2013-12-28 00:57:23
【问题描述】:

我将 Spring MVC 应用程序 (3.2.5) Spring Security 库(版本 3.1.4)添加到我的 pom.xml 以使用 Spring Security(请参阅稍后添加的依赖项)。但现在我在配置类中使用的注释不起作用。

我做错了什么?

这是一个 Eclipse 错误:

错误信息:

pom.xml 中的 Spring 依赖项(注释与它一起使用):

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

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

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

pom.xml 中的 Spring Security 依赖项(注释不起作用):

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>3.1.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>3.1.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>3.1.4.RELEASE</version>
    </dependency>

【问题讨论】:

  • 你在使用maven eclipse插件吗?
  • @reagten - 是的,我愿意。

标签: eclipse spring maven dependencies


【解决方案1】:

由于 spring-security-core 3.1.4.RELEASE 依赖于 spring-context 3.0.7.RELEASE,你需要显式地为 spring-context 3.2.5.RELEASE 添加一个依赖来强制 maven 使用最新版本。

至少 .ComponentScan 仅在 3.1 中添加。

编辑: 正如M所说。 Deinum,使用&lt;dependencyManagement&gt; 块来定义所有依赖项版本。因此,您可以在“主”&lt;dependencies&gt; 块中省略任何 &lt;version&gt; 标记。

【讨论】:

  • 正确。一般来说,我在 maven 中使用 &lt;dependencyManagement /&gt; 块来强制特定框架的版本。
  • 好吧,我已经解决了我原来问题的依赖问题,但是现在我需要扩展WebSecurityConfigurerAdapter,并且这个类是在 Spring Security 3.2.0.RC 中添加的。能解决吗?
猜你喜欢
  • 2021-09-27
  • 2020-10-25
  • 2017-01-14
  • 1970-01-01
  • 2018-02-22
  • 2012-01-01
  • 2011-10-05
  • 2012-09-26
  • 2015-10-26
相关资源
最近更新 更多