Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将SpringSecurity2.5升级到3.1-java.lang.NoClassDefFoundError:org/springframework/Security/Authentication_Java_Spring Security_Migration_Noclassdeffounderror - Fatal编程技术网

将SpringSecurity2.5升级到3.1-java.lang.NoClassDefFoundError:org/springframework/Security/Authentication

将SpringSecurity2.5升级到3.1-java.lang.NoClassDefFoundError:org/springframework/Security/Authentication,java,spring-security,migration,noclassdeffounderror,Java,Spring Security,Migration,Noclassdeffounderror,这个问题很难解决。通常的情况是,继承了一个维护非常差的JavaWeb应用程序,没有单元测试和各种古老的jar依赖关系,没有版本信息转储到使用Ant构建的lib目录中。为了更好地维护和理解依赖关系,我迁移到Maven。随后,我意识到Spring的版本已经很旧了(Spring2.x和SpringSecurity2.0.3)。我成功升级到Spring2.5。我现在已经开始将Spring迁移到3.1.2.RELEASE,将Spring Security迁移到3.1.3.RELEASE 一切都经过编译,我

这个问题很难解决。通常的情况是,继承了一个维护非常差的JavaWeb应用程序,没有单元测试和各种古老的jar依赖关系,没有版本信息转储到使用Ant构建的lib目录中。为了更好地维护和理解依赖关系,我迁移到Maven。随后,我意识到Spring的版本已经很旧了(Spring2.x和SpringSecurity2.0.3)。我成功升级到Spring2.5。我现在已经开始将Spring迁移到3.1.2.RELEASE,将Spring Security迁移到3.1.3.RELEASE

一切都经过编译,我也没有发现任何名称空间问题(在SpringXMLConfigs的头文件中声明),但在作为WAR文件部署到Tomcat容器中时失败。日志文件报告:

Could not instantiate bean class [com.mydomain.repository.ReportDaoImpl]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/security/Authentication
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
我检查过了,org.springframework.security.Authentication属于旧的Spring安全jar(2.0.4)

我当前的Maven依赖项如下所示:

<spring.version>3.1.2.RELEASE</spring.version>

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

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

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

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

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

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

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

    <!--  SPRING SECURITY -->

             <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-acl</artifactId>
        <version>3.1.3.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.1.3.RELEASE</version>
    </dependency>

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

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>3.1.3.RELEASE</version>
    </dependency>

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

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-crypto</artifactId>
        <version>3.1.3.RELEASE</version>
    </dependency>
<bean id="reportDao" class="com.mydomain.repository.ReportDaoImpl">
    <property name="dataSource" ref="myDataSource" />
</bean>
我想看起来不错

可交付WAR文件的WEB-INF/lib目录中唯一的spring JAR(请确定)是:

./spring-aop-3.0.7.RELEASE.jar
./spring-asm-3.0.7.RELEASE.jar
./spring-beans-3.0.7.RELEASE.jar
./spring-context-3.0.7.RELEASE.jar
./spring-context-support-3.0.7.RELEASE.jar
./spring-core-3.0.7.RELEASE.jar
./spring-expression-3.0.7.RELEASE.jar
./spring-jdbc-3.0.7.RELEASE.jar
./spring-security-acl-3.1.3.RELEASE.jar
./spring-security-config-3.1.3.RELEASE.jar
./spring-security-core-3.1.3.RELEASE.jar
./spring-security-crypto-3.1.3.RELEASE.jar
./spring-security-taglibs-3.1.3.RELEASE.jar
./spring-security-web-3.1.3.RELEASE.jar
./spring-tx-3.0.7.RELEASE.jar
./spring-web-3.0.7.RELEASE.jar
./spring-webmvc-3.0.7.RELEASE.jar
同样,这看起来很明智

将源代码变灰以进行“身份验证”没有帮助。这看起来像是一个可传递的运行时依赖性问题。它在编译时不会被注意到,也不会在任何地方声明为一级依赖项。但是在运行时(在Tomcat6容器中),当部署时,会请求对旧库文件的恶意引用


作为预防措施,将删除我的Tomcat实例并从头开始。

好的,最终解决了这个特殊问题。NoClassDefFoundError正是它在tin上所说的。正如Luke Taylor所问的“你绝对确定你重新编译了吗?”是和否。我确实重新编译、清理了target(使用Maven)等。第一次使用反编译器查看生成的类“XXXDao”的源代码时,我看到了我的更改。但我也注意到,当我从java源代码中添加/删除几行代码时,stacktrace中的错误仍然保留在相同的(随机)行号上。这就解释了为什么我会得到一个陈旧的.class文件。事实证明,Maven和/或Eclipse(m2eclipse插件)以某种方式成功地将类文件编译到我的核心项目(非目标)的WEB-INF/classes目录中,并用一些类非决定性地覆盖了目标中的WEB-INF/classes目录。更奇怪的是,它总是在将类压缩为.WAR时部署旧类。所以你有一个例子,分解的内容看起来是正确的,但实际上是压缩的WAR文件,有不同的类


经验教训-如果您遇到这种行为,请仔细检查编译步骤,并尝试找出旧类文件(引用旧身份验证类)是如何进入新构建的。感谢那些对这篇文章有贡献的人的指点

你能发布
报告daoimpl
的类吗?这似乎是此类自动布线中的一个问题。此外,spring配置中的自动布线是如何触发的?没有自动布线。这是老式的XML配置。已将上述相关部分作为更新。应用程序配置由容器通过web.xml(我相信您很熟悉)引入。我会仔细检查您的类路径(编译和运行时),因为maven POM很少是您最终得到的定义语句。运行“mvn-X”并检查列出的所有JAR,以确保您没有针对2.0.X JAR进行编译。另外,请对java源代码中的“Authentication”和“org.springframework.security”进行grep,并检查使用Spring安全类的所有代码中的包是否正确。@Luke Taylor非常感谢您抽出时间。您已经编写了一个很棒的框架,并对您宝贵的输入进行了分析。我已经检查了身份验证。我只在导入中引用org.springframework.security.core.Authentication。当然,你打开mvn-X是绝对正确的。我现在再检查一遍。只是多一点信息。我下载了SpringSecurity3.1.3示例应用程序,并查看了联系人示例是如何设置的。它使用Spring(main)3.0.7和Spring Security 3.1.3,因此我将Spring(main)更改为3.0.7。现在问题变为java.lang.NoClassDefFoundError:org/slf4j/LoggerFactory,我将把它作为一个运行时依赖项放到pom.xml中,看看会发生什么。如果这触发了任何指针,请让我知道。再次感谢。
<bean id="reportDao" class="com.mydomain.repository.ReportDaoImpl">
    <property name="dataSource" ref="myDataSource" />
</bean>
 <bean id="parentDataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
</bean>

<bean id="myDataSource" parent="parentDataSource">
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>
   org.springframework:spring-webmvc:jar:3.0.7.RELEASE:compile
    org.springframework:spring-asm:jar:3.0.7.RELEASE:compile
    org.springframework:spring-beans:jar:3.0.7.RELEASE:compile
    org.springframework:spring-expression:jar:3.0.7.RELEASE:compile
    org.springframework:spring-web:jar:3.0.7.RELEASE:compile
 org.springframework:spring-aop:jar:3.0.7.RELEASE:compile
    aopalliance:aopalliance:jar:1.0:compile
 org.springframework:spring-context:jar:3.0.7.RELEASE:compile
 org.springframework:spring-context-support:jar:3.0.7.RELEASE:compile
 org.springframework:spring-core:jar:3.0.7.RELEASE:compile
 org.springframework:spring-tx:jar:3.0.7.RELEASE:compile
 org.springframework:spring-jdbc:jar:3.0.7.RELEASE:compile
 org.springframework.security:spring-security-acl:jar:3.1.3.RELEASE:compile
 org.springframework.security:spring-security-config:jar:3.1.3.RELEASE:compile
 org.springframework.security:spring-security-core:jar:3.1.3.RELEASE:compile
 org.springframework.security:spring-security-taglibs:jar:3.1.3.RELEASE:compile
 org.springframework.security:spring-security-web:jar:3.1.3.RELEASE:compile
 org.springframework.security:spring-security-crypto:jar:3.1.3.RELEASE:compile
./spring-aop-3.0.7.RELEASE.jar
./spring-asm-3.0.7.RELEASE.jar
./spring-beans-3.0.7.RELEASE.jar
./spring-context-3.0.7.RELEASE.jar
./spring-context-support-3.0.7.RELEASE.jar
./spring-core-3.0.7.RELEASE.jar
./spring-expression-3.0.7.RELEASE.jar
./spring-jdbc-3.0.7.RELEASE.jar
./spring-security-acl-3.1.3.RELEASE.jar
./spring-security-config-3.1.3.RELEASE.jar
./spring-security-core-3.1.3.RELEASE.jar
./spring-security-crypto-3.1.3.RELEASE.jar
./spring-security-taglibs-3.1.3.RELEASE.jar
./spring-security-web-3.1.3.RELEASE.jar
./spring-tx-3.0.7.RELEASE.jar
./spring-web-3.0.7.RELEASE.jar
./spring-webmvc-3.0.7.RELEASE.jar