无法检索“entityManagerFactory”使用杰罗尼莫

发布于 2024-09-03 06:00:48 字数 1683 浏览 6 评论 0原文

我刚刚开始学习Spring框架。我当前的目标是通过 Geronimo 服务器上的 JPA(TopLink** 提供程序)从我的 bean 访问数据库。但我无法克服获取entityManagerFactory 的问题。

我得到的异常:

java.lang.IllegalStateException: 类加载器 [org.apache.geronimo.kernel.config.MultiParentClassLoader] 不提供 'addTransformer(ClassFileTransformer)' 方法。指定自定义 LoadTimeWeaver 或启动您的 Java 带有Spring代理的虚拟机: -javaagent:spring-agent.jar

我访问它的方式:

    <context:load-time-weaver />

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceXmlLocation" value="classpath:/META-INF/persistence.xml" />
    </bean>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <tx:annotation-driven />

如果有人可以在不使用“-javaagent:spring-agent.jar”选项的情况下帮助我,我将非常感激。


正在寻找解决方案。第一次尝试。

遵循“axtavt” 建议,我找到了为 Tomcat 上的 Web 应用程序指定特殊类加载器的示例。它使用 context.xml 文件来实现此目的。尽管我的 Geronimo 使用 Tomcat,但我没有成功实现 context.xml。正如接下来所说 手册context.xml<的替代方案Geronimo 的 /em> 是 geronimo-tomcat.xml,但它的语法不提供任何更改类加载器的可能性。我还需要帮助!


I have just started studying Spring framework. My current goal is to access database from my bean through JPA (TopLink** provider) on Geronimo server. But I can't overcome the problem of getting entityManagerFactory.

The exception I get:

java.lang.IllegalStateException:
ClassLoader
[org.apache.geronimo.kernel.config.MultiParentClassLoader]
does NOT provide an
'addTransformer(ClassFileTransformer)'
method. Specify a custom
LoadTimeWeaver or start your Java
virtual machine with Spring's agent:
-javaagent:spring-agent.jar

The way I access it:

    <context:load-time-weaver />

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceXmlLocation" value="classpath:/META-INF/persistence.xml" />
    </bean>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <tx:annotation-driven />

I will be very grateful if anyone can help me without using "-javaagent:spring-agent.jar" option.


Searching a solution. First attempt.

Following "axtavt" advice, I found example of specifying special class loader for your web application on Tomcat. It uses context.xml file for that purpose. Although my Geronimo uses Tomcat, I didn't succeed implementing context.xml. As is said in the next
manual the alternative for context.xml for Geronimo is geronimo-tomcat.xml, but it's syntax doesn't provide any possibilities for changing classloader. I still need help!


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

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

发布评论

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

评论(1

叹沉浮 2024-09-10 06:00:49

Toplink 需要加载时编织支持。 我想在 Geronimo 中可以通过使用 META-INF/context.xml 并将仪器 jar 放入 lib 文件夹中进行配置,就像在 Tomcat 中一样,请参阅 此处.

编辑:所以,你的问题是 Toplink 需要类转换支持。当在 Spring 的配置中配置 Toplink 的实体管理器 (LocalContainerEntityManagerFactoryBean) 时,它会尝试使用 Spring 对类转换的支持 () ,但是 Spring 没有对 Geronimo 中的类转换提供内置支持。因此,您有 3 个选择:

  1. 使用不需要类转换的 JPA 实现来代替 Toplink(例如 Hibernate)
  2. 不要在 Spring 配置文件中配置 Toplink 的实体管理器。使用 Geronimo 配置来配置它(我不知道如何)并使用 JNDI 获取它。
  3. 对于狂热者:实现自定义 LoadTimeWeaver for Geronimo(我猜,它将使用 TransformerAgent.addTransformer())。

Toplink requires a load-time weaving support. I guess in Geronimo it can be configured by using META-INF/context.xml and putting instrumentation jar into lib folder, as in Tomcat, see here.

EDIT: So, your problem is that Toplink requires class transformation support. When Toplink's entity manager is configured in Spring's configuration (LocalContainerEntityManagerFactoryBean), it tries to use Spring's support for class transformation (<context:load-time-weaver />), but Spring doesn't have a built-in support for class transformation in Geronimo. So, you have 3 options:

  1. Use JPA implementation which doesn't require class transformation instead of Toplink (for example, Hibernate)
  2. Don't configure Toplink's entity manager in Spring configuration file. Configure it using Geronimo configuration (I don't know how) and obtain it using JNDI.
  3. For maniacs: Implement a custom LoadTimeWeaver for Geronimo (I guess, it will use TransformerAgent.addTransformer()).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文