【问题标题】:OpenJPA enhancing a Spring ROO batch applicationOpenJPA 增强 Spring ROO 批处理应用程序
【发布时间】:2011-01-21 14:17:11
【问题描述】:

我对 OpenJPA 很陌生,想运行我的应用程序。我创建了一个 main 方法并在那里加载上下文 XML 并启动一个事务来运行我的服务。但是当我运行它时,我得到了一个

org.apache.openjpa.persistence.ArgumentException:“class tld.myproject.domain.Entity”类型尚未增强。

我搜索了一下,发现我需要添加一个增强器,所以我在命令行中添加了以下内容:

-javaagent:/home/me/.m2/repository/org/apache/openjpa/openjpa/2.0.1/openjpa-2.0.1.jar

现在,我明白了

java.lang.LinkageError: loader (instance of sun/misc/Launcher$AppClassLoader): 尝试重复的类定义名称:“org/springframework/stereotype/Controller”

也许只是时间不早了,我的头还没有拧紧,但是,这里到底发生了什么事?我需要做什么才能让我的 Spring Roo 批处理项目运行?

干杯

尼克

PS,我可能应该在我的 pom.xml 中补充一点,Roo 已经为编译阶段定义了一个增强器

【问题讨论】:

    标签: java spring-roo openjpa


    【解决方案1】:

    您可能应该使用编译时增强而不是 javaagent 的运行时增强。

    如果您使用的是 m2eclipse(您可能会这样做),那么使用以下内容就足够了:

    <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <properties>
            <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.H2Dictionary"/>
            <!-- value="buildSchema" to runtime forward map the DDL SQL; value="validate" makes no changes to the database -->
            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
            <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
        </properties>
    </persistence-unit>
    

    在你的 pom.xml 的 build 部分你应该有类似的东西:

                          <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>openjpa-maven-plugin</artifactId>
                            <version>1.2</version>
                            <configuration>
                                <includes>**/*.class</includes>
                                <excludes>**/*_Roo_*.class</excludes>
                                <addDefaultConstructor>true</addDefaultConstructor>
                            </configuration>
                            <executions>
                                <execution>
                                    <id>enhancer</id>
                                    <phase>compile</phase>
                                    <goals>
                                        <goal>enhance</goal>
                                    </goals>
                                </execution>
                                <execution>
                                    <id>test-enhancer</id>
                                    <phase>test-compile</phase>
                                    <goals>
                                        <goal>enhance</goal>
                                    </goals>
                                </execution>
                            </executions>
                            <dependencies>
                                <dependency>
                                    <groupId>org.apache.openjpa</groupId>
                                    <artifactId>openjpa</artifactId>
                                    <version>${openjpa.version}</version>
                                    <exclusions>
                                        <exclusion>
                                            <groupId>commons-logging</groupId>
                                            <artifactId>commons-logging</artifactId>
                                        </exclusion>
                                        <exclusion>
                                            <groupId>org.apache.geronimo.specs</groupId>
                                            <artifactId>geronimo-jms_1.1_spec</artifactId>
                                        </exclusion>
                                    </exclusions>
                                </dependency>
                            </dependencies>
                        </plugin>
    

    请注意,roo 可能会生成不同的 xml sn-p 可能无法正常工作(IIRC 它使用不同的输出目录)。

    清理后,您的项目类应该得到增强。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-22
      • 1970-01-01
      • 2020-10-09
      • 2017-07-28
      • 2023-04-10
      • 1970-01-01
      相关资源
      最近更新 更多