Spring 安防:java.lang.ClassNotFoundException:org.springframework.dao.support.DaoSupport

chy5wohz  于 2023-03-16  发布在  Spring
关注(0)|答案(3)|浏览(209)

我正在用Spring开发应用程序,并使用Spring安全性登录postgres数据库,但我无法解决此错误:

Caused by: java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport
at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_25]
at java.lang.ClassLoader.defineClass(ClassLoader.java:792) [rt.jar:1.7.0_25]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) [rt.jar:1.7.0_25]
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:391)
... 54 more
Caused by: java.lang.ClassNotFoundException: org.springframework.dao.support.DaoSupport from [Module "deployment.SpringSecurityTest8.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
... 59 more

09:07:09,554 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl in Module "deployment.SpringSecurityTest8.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/security/core/userdetails/jdbc/JdbcDaoImpl (Module "deployment.SpringSecurityTest8.war:main" from Service Module Loader)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:396)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73)
at org.jboss.modules.Module.loadModuleClass(Module.java:517)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_25]
 Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.core.support.JdbcDaoSupport from [Module "deployment.SpringSecurityTest8.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
... 46 more

09:07:09,685 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.security.provisioning.JdbcUserDetailsManager in Module "deployment.SpringSecurityTest8.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/security/provisioning/JdbcUserDetailsManager (Module "deployment.SpringSecurityTest8.war:main" from Service Module Loader)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:396)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73)
at org.jboss.modules.Module.loadModuleClass(Module.java:517)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)

这是spring-security-配置文件

<beans:beans xmlns="http://www.springframework.org/schema/security"
 xmlns:beans="http://www.springframework.org/schema/beans" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 http://www.springframework.org/schema/security
 http://www.springframework.org/schema/security/spring-security-3.1.xsd">



 <http auto-config="true" use-expressions="true">
 <intercept-url pattern="/admin**" access="ROLE_ADMIN" />
 <intercept-url pattern="/emp**" access="ROLE_EMP" />
 </http>

 <beans:bean id='dataSource' 
class='org.springframework.jdbc.datasource.DriverManagerDataSource'>
<beans:property name='driverClassName' value='org.postgresql.Driver' />
<beans:property name='url' value='jdbc:postgresql://localhost:5432/postgres'      />
<beans:property name='username' value='postgres' />
<beans:property name='password' value='po' />
<authentication-manager>
  <authentication-provider>
  <jdbc-user-service
  data-source-ref="dataSource"
  users-by-username-query='SELECT username, "password", true FROM          "DataB".users where username=?'
 authorities-by-username-query='select u1.username, u2.authority from     "DataB"."users" u1, 
"DataB"."authorities" u2 where u1.username = u2.username and u1.username     =?' />

   </authentication-provider>
  </authentication-manager>

有人能帮忙吗?我花了很多时间,还是能找出问题所在。

qyyhg6bp

qyyhg6bp1#

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>4.1.5.RELEASE</version>
  </dependency>

事实上

lyfkaqu1

lyfkaqu12#

看起来你错过了类路径中的spring-dao.jar。那个jar包含类org.springframework.dao.support.DaoSupport
下载它并将其添加到类路径中。

8tntrjer

8tntrjer3#

值得注意的是,spring-jdbc取决于:

spring-beans
spring-core
spring-tx

(at撰写时间)
如果你的项目没有像maven这样的好工具来处理很多子依赖项,你仍然可以通过访问maven仓库来检查库依赖项,查看给定版本的pom.xml,检查依赖项部分,看看你可能遗漏了什么。
例如spring-jdbc version 6.0.6 pom.xml

相关问题