spring - 在Grails中加载bean时发生ClassNotFound异常

标签 spring grails grails-2.0

我有一个jar文件,其中包含在applicationContext.xml中定义的bean。我已经将jar文件添加到lib目录中,并且还将我的构建配置修改为

runtime "content:content-examiner-data:1.0"



我在resource.groovy中定义了如下的bean

beans = {

importBeans("classpath*:/applicationContext.xml")

}



Bean的定义如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <mongo:mongo host="localhost" port="27017" />


    <bean class="org.springframework.data.mongodb.core.MongoTemplate"
        id="mongoTemplate">
        <constructor-arg ref="mongo"></constructor-arg>
        <constructor-arg value="documents"></constructor-arg>
    </bean>
    <mongo:db-factory id="mongoDbFactory" dbname="database" mongo-ref="mongo"/>
  <mongo:mapping-converter id="converter" />

  <bean id="gridTemplate" class="org.springframework.data.mongodb.gridfs.GridFsTemplate">
    <constructor-arg ref="mongoDbFactory" />
    <constructor-arg ref="converter" />
  </bean>

  <bean id="ceMongoStore" class="gov.ic.isso.ce.service.mongoimpl.CEStorageMongoImpl">
    <constructor-arg ref="mongoTemplate" />
    <constructor-arg ref="gridTemplate" />
    <constructor-arg value="cedocs" />
  </bean>
</beans>

使用run-app选项运行应用程序时出现以下错误
 Error 2013-02-07 16:08:24,806 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error executing bootstraps: Cannot find class [gov.ic.isso.ce.service.mongoimpl.CEStorageMongoImpl] for bean with name 'ceMongoStore' defined in URL [jar:file:/C:/development/projects/sentrytrunk/Latest/fc/content-examiner-web/lib/content-examiner-data-1.0.jar!/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: gov.ic.isso.ce.service.mongoimpl.CEStorageMongoImpl
Message: Cannot find class [gov.ic.isso.ce.service.mongoimpl.CEStorageMongoImpl] for bean with name 'ceMongoStore' defined in URL [jar:file:/C:/development/projects/sentrytrunk/Latest/fc/content-examiner-web/lib/content-examiner-data-1.0.jar!/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: gov.ic.isso.ce.service.mongoimpl.CEStorageMongoImpl
   Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   662 | run . .  in java.lang.Thread

Caused by ClassNotFoundException: gov.ic.isso.ce.service.mongoimpl.CEStorageMongoImpl
->> 202 | run      in java.net.URLClassLoader$1

当我使用jar tvf转储jar文件时,得到以下输出
1472 Thu Feb 07 16:00:30 EST 2013 applicationContext.xml
   709 Thu Feb 07 16:00:30 EST 2013 gov/ic/isso/ce/data/CEStorage.class
  1946 Thu Feb 07 16:00:30 EST 2013 gov/ic/isso/ce/data/model/document/Document.class
  1186 Thu Feb 07 16:00:30 EST 2013 gov/ic/isso/ce/data/model/document/DocumentStatus.class
  5995 Thu Feb 07 16:00:30 EST 2013 gov/ic/isso/ce/service/mongoimpl/CEStorageMongoImpl.class
     0 Thu Feb 07 16:00:34 EST 2013 META-INF/maven/
     0 Thu Feb 07 16:00:34 EST 2013 META-INF/maven/gov.ic.isso.content-examiner/
     0 Thu Feb 07 16:00:34 EST 2013 META-INF/maven/gov.ic.isso.content-examiner/content-examiner-data/
  1925 Thu Feb 07 15:54:44 EST 2013 META-INF/maven/gov.ic.isso.content-examiner/content-examiner-data/pom.xml
   146 Thu Feb 07 16:00:34 EST 2013 META-INF/maven/gov.ic.isso.content-examiner/content-examiner-data/pom.properties

最佳答案

删除runtime "content:content-examiner-data:1.0"或jar文件-您只需要一个即可。如果将jar文件添加到lib目录,则需要运行grails compile --refresh-dependencies将其添加到类路径中

关于spring - 在Grails中加载bean时发生ClassNotFound异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14761169/

相关文章:

java - Spring Boot 中未调用 Spring Batch 作业

java - 如何将我的 spring xml 配置移到我的 web 应用程序之外?

spring - 如何处理持久化之前使用 Hibernate 验证的内部 @Entity 类的 Spring BindingResult 异常

hibernate - Spring + Hibernate +JTA - HibernateTransactionManager 或 JTATransactionManager

java - Grails 验证中的自定义字段名称

java - Grails 一对多关系

authentication - Grails 3 中的 Jetty 容器身份验证

spring - 错误: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

spring - 如何将Grails ElasticSearch插件更新为ElasticSearch的最新版本?

database - 何时以及如何在 Grails 中创建索引?