OpenJPA 增强 Spring ROO 批处理应用程序

发布于 2024-10-12 22:04:50 字数 646 浏览 3 评论 0原文

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

org.apache.openjpa.persistence.ArgumentException: The type "class tld.myproject.域.实体”尚未得到增强。

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

-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): attempts 重复的类定义名称:“org/springframework/stereotype/Controller”

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

干杯

Nik

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

I'm quite new to OpenJPA and wanted to run my application. I've made a main method and load the context XML there and fire up a transaction to run my service in. But when I run it I get a

org.apache.openjpa.persistence.ArgumentException: The type "class tld.myproject.domain.Entity" has not been enhanced.

I Google'd around and found that I'd need to add an enhancer, so I added the following to my command line:

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

Now, I get

java.lang.LinkageError: loader (instance of sun/misc/Launcher$AppClassLoader): attempted duplicate class definition for name: "org/springframework/stereotype/Controller"

Perhaps it's just getting late and I don't have my head screwed right on, but, what on earth is going on here? What do I need to do to get my Spring Roo batch project running?

Cheers

Nik

PS, I should probably add that in my pom.xml Roo has defined an enhancer for the compile phase

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独陪着我 2024-10-19 22:04:50

您可能应该使用 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 的构建部分中,您应该有类似的内容:

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

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

You should probably use compile time enhancement instead of runtime enhancement with javaagent.

If you're using m2eclipse (you probably do) it would be enough to use something like:

<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>

and inside build section of your pom.xml you should have something like:

                      <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>

Please note that roo might generate different xml snippet that might not work (IIRC it uses different output directory).

After you clean your project classes should be enhanced.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文