0

我对 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:加载程序(sun/misc/Launcher$AppClassLoader 的实例):尝试重复的类定义名称:“org/springframework/stereotype/Controller”

也许只是太晚了,我的头还没拧好,但是,这里到底发生了什么?我需要做什么才能让我的 Spring Roo 批处理项目运行?

干杯

尼克

PS,我可能应该在我的 pom.xml 中添加 Roo 为编译阶段定义了一个增强器

4

1 回答 1

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 片段(IIRC 它使用不同的输出目录)。

在你清理你的项目类之后应该得到增强。

于 2011-03-12T21:51:57.187 回答