问题
I am trying to use a jdbcTemplate.query
and I get the class not found error. I am using spring-dao 2.0.8 and looked inside the library and couldn't find any DuplicateKeyException
class indeed. From maven repository this seems to be the latest release for spring-dao.
The code where I am getting the error is:
ResultSet resultSet = (ResultSet)jdbcTemplate.query (query, new ResultSetExtractor<ResultSet>() {
@Override
public ResultSet extractData(ResultSet rs) throws SQLException, DataAccessException {
return rs;
}
});
And the stack:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/dao/DuplicateKeyException
at org.springframework.jdbc.support.JdbcAccessor.getExceptionTranslator(JdbcAccessor.java:99)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:407)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:456)
at DAO.MySQLAccess.getAccounts(MySQLAccess.java:95)
Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DuplicateKeyException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 7 more
Isn't this the latest release or why is it giving the error in the first place?
回答1:
Sounds like you have a jar missing from the classpath. I guess you're not using maven.
I searched for jars containing this class and came up with this.
http://mavenhub.com/c/org/springframework/dao/DuplicateKeyException/jar
Looks like you need the org.springframework.transaction jar. Or use maven and it should work out your dependencies for you.
来源:https://stackoverflow.com/questions/20499200/spring-dao-class-not-found-org-springframework-dao-duplicatekeyexception