Spring的LocalContainerEntityManagerFactoryBean可以在J2SE环境中使用吗?
我在 Glassfish 中使用 Spring,并且需要对其进行配置,以便它也可以在容器外部工作,主要用于开发目的。
我不确定并且找不到答案的是,我是否可以在没有容器的情况下使用 LocalContainerEntityManagerFactoryBean
类。
从它的名字来看,LocalContainer
,似乎我可以,但是在 docs 它说:
创建 JPA 的 FactoryBean EntityManagerFactory根据 JPA 的标准容器引导程序 合同
所以我不确定这个问题。
谢谢,
一泰
I'm using Spring in Glassfish and I have the need to configure it so it also works outside of the container, mainly for development purposes.
What I'm uncertain of, and couldn't find the answer to, was whether I can use the LocalContainerEntityManagerFactoryBean
class without a container.
From its name, LocalContainer
, it seems I can but in the docs it says:
FactoryBean that creates a JPA
EntityManagerFactory according to
JPA's standard container bootstrap
contract
so I'm uncertain about this issue.
Thanks,
Ittai
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只是想指出 Spring 支持在容器外部运行 JPA 内容,并且不需要任何事务管理器的方式。要问的问题是您是否正在使用 Spring 的声明式事务管理(例如“@Transactional”)。
如果是,那么您需要提供“PlatformTransactionManager”的实现。在这里,您仍然不需要使用完整的 JTA 支持(如上例中 Atomikos 提供的那样)。只要您不使用“XA”做任何事情,您就可以简单地使用 JpaTransactionManager 实例(它需要对实体管理器工厂的引用) “等等。如果你正在做 XA,那么 Atomikos、Bitronix 或任何其他选项都可以。你可以看看这个例子 http://blog.springsource.com/2011/08/15/configuring-spring-and-jta- without-full-java-ee/ 演示了如何使用 JTA(例如,使用 JPA 和 JMS),
因此,重申一下,如果您只是执行简单的 JPA(连接到一个数据库),那么您就不需要这样做。不需要 JTA,并且您绝对不需要 GlassFish 如果您需要 XA,那么您仍然可以使用上面建议的第三方 JTA 提供程序,并且您仍然不需要 Glassfish
最后,如果您确实愿意的话 。如果要同时维护 GlassFish + JTA 和一个仅在本地工作的单独 JPA,以便在更快的容器上进行快速开发,您可能会考虑即将推出的 Spring 3.1,它具有“配置文件”功能,允许您有条件地为每个环境定义 Bean(例如,“生产、 ”或“开发”或“云”,或者任何你想要的。)
I just wanted to note that Spring supports running the JPA stuff outside of a container, and doesn't require anything in the way of a transaction manager. The question to ask is whether you are using Spring's declarative transaction management (e.g., "@Transactional").
If you are, then you need to provide an implementation of "PlatformTransactionManager." Here still, you do NOT need to use full on JTA support (as provided by Atomikos in the above example. YOu can simply use a JpaTransactionManager instance (which expects a reference to the entity manager factory) provided you are not doing anything with "XA" etc. If you are doing XA, then Atomikos, or Bitronix or any of a number of other options are just fine. You might look at this example http://blog.springsource.com/2011/08/15/configuring-spring-and-jta-without-full-java-ee/ which demonstrates how to use JTA (with JPA and JMS, for example).
So, reiterating, if you're just doing simple JPA (connecting to one database) then you don't need JTA, and you definitely don't need GlassFish. If you need XA, then you can still use a third party JTA provider as the responder above suggested, and you still don't need Glassfish.
Finally, if you truly wish to maintain both GlassFish + JTA, and a separate JPA that works only locally for rapid development on a faster container, you might consider the imminent Spring 3.1, which features "profiles" to allow you to conditionally define beans per environment (e.g., "production," or "dev," or "cloud," or whatever you'd like.)
是的,这是可能的,但你需要提供一个事务管理器(如 Atomikos)。其余配置相同。
这是一个例子:
Yes, it's possible, but you need to provide a transaction manager (like Atomikos). The rest of the configuration is the same.
This is an example: