- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 2 个 Weblogic 数据源;在我的 XML 配置中,我有 2 个持久性单元、2 个 entityManagerFactories 和 2 个 transactionManagers。文件如下:
persistence.xml:
<persistence-unit name="modelPersistence" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
</persistence-unit>
<persistence-unit name="orderPersistence" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
</persistence-unit>
config.xml:
<!-- transactionManagers -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="transactionManagerLegacy" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactoryLegacy" />
</bean>
<!-- entityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSourceModel"/>
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
<property name="persistenceUnitName" value="modelPersistence" />
<property name="jpaProperties">
<props>
<prop key="eclipselink.logging.level">FINE</prop>
</props>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform" value="org.eclipse.persistence.platform.database.OraclePlatform" />
<property name="generateDdl" value="true"/>
<property name="showSql" value="true"/>
</bean>
</property>
</bean>
<!-- entityManagerFactoryLegacy -->
<bean id="entityManagerFactoryLegacy" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSourceOrder"/>
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
<property name="persistenceUnitName" value="orderPersistence" />
<property name="jpaProperties">
<props>
<prop key="eclipselink.logging.level">FINE</prop>
</props>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform" value="org.eclipse.persistence.platform.database.OraclePlatform" />
<property name="generateDdl" value="true"/>
<property name="showSql" value="true"/>
</bean>
</property>
</bean>
<!-- data source 1-->
<bean id="dataSourceModel" class="org.springframework.jndi.JndiObjectFactoryBean" depends-on="model-datasource-jndi">
<property name="jndiName" ref="model-datasource-jndi" />
<property name="resourceRef" value="true" />
</bean>
<!-- data source 2-->
<bean id="dataSourceOrder" class="org.springframework.jndi.JndiObjectFactoryBean" depends-on="order-datasource-jndi">
<property name="jndiName" ref="order-datasource-jndi" />
<property name="resourceRef" value="true" />
</bean>
<!-- configure persistenceUnitManager -->
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
<property name="dataSources">
<map>
<entry key="jdbc/MODEL-DS" value-ref="dataSourceModel"/>
<entry key="jdbc/ORDER-DS" value-ref="dataSourceOrder"/>
</map>
</property>
</bean>
<jpa:repositories base-package="org.codingpedia.demo.repositories.ModelRepository" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/>
<jpa:repositories base-package="org.codingpedia.demo.repositories.OrderRepository" entity-manager-factory-ref="entityManagerFactoryLegacy" transaction-manager-ref="transactionManagerLegacy"/>
模型库:
@Repository ("ModelRepo")
@PersistenceContext(unitName = "modelPersistence")
public interface ModelRepository extends JpaRepository<Model, String> {}
orderRepository:
@Repository ("OrderRepo")
@PersistenceContext(unitName = "orderPersistence")
public interface OrderRepository extends JpaRepository<Model, String> {}
关于处理多个事务管理器的正确注释有什么建议吗?我还缺少其他东西吗?其他堆栈溢出示例使用 DAO,我发现它们对我没有帮助,因为我正在使用存储库、模型和 Controller java 文件。我也没有使用 hibernate,很多示例也引用了它。感谢您的见解。
我收到以下错误:
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined: expected single matching bean but found 2: transactionManagerLegacy,transactionManager
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:365)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineTransactionManager(TransactionAspectSupport.java:370)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:271)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy120.findAll(Unknown Source)
at org.codingpedia.demo.controller.BaseController.index(BaseController.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:243)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3432)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
最佳答案
您可以使用:
@Transactional("transactionManagerName")
参见 org.springframework.transaction.annotation.Transactional (@Transactional) 注解 javadoc:
/**
* A qualifier value for the specified transaction.
* <p>May be used to determine the target transaction manager,
* matching the qualifier value (or the bean name) of a specific
* {@link org.springframework.transaction.PlatformTransactionManager}
* bean definition.
*/
String value() default "";
关于java - 没有定义 [org.springframework.transaction.PlatformTransactionManager] 类型的合格 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33129201/
我正在致力于将 Spring Security OAuth2 与 JWT token 集成到 Spring Boot 项目中。我的身份验证服务器的配置类似于 sample project 中的配置。
我正在实现一个 JDBC 数据库访问 API(基本上是一个包装器),并使用 Spring JdbcTemplate 和 PlatformTransactionManager 来处理事务操作。一切看起来
我希望改造我们现有的事务 API 以使用 Spring 的 PlatformTransactionManager,这样 Spring 将管理我们的事务。我按如下方式链接了我的 DataSource:
我正在使用 wicket 开发一个通用的 CRUD 应用程序,它可以使用 AbstractDao 模式的实现来编辑任何 Spring/JPA 实体,例如 UserDaoImpl 、 ForumDaoI
当尝试在事务之间测试 Hibernate(版本 4)EHCache 的缓存功能时 - 它失败了:无法为测试上下文的@Transactional 测试检索 PlatformTransactionMana
我有一个 FooService,我希望它仅在 PlatformTransactionManager 可用时可用。 如果我这样定义我的服务并且没有 PlatformTransactionManager
我已成功使用 inMemory 功能来创建 HelloWorld Spring OAuth2。现在,我想使用 MySql 而不是 inMemory。以下是我迄今为止尝试过的代码。 当我尝试通过 Pos
我是 Spring 世界的新手。我一直在尝试使用 spring 数据编写一个基本应用程序,使用 Hibernate 和 MYSql 数据库编写 JPA。我看到错误: No matching Platf
通过替换 BASIC auth,我成功地将 OAuth2 集成到我以前的应用程序(REST 服务)中。 然后我得到以下异常: No qualifying bean of type [org.sprin
我正在开发 Spring Boot 应用程序,该应用程序已经在其 applicationContext.xml 文件中建立了数据库连接以及必要的事务管理器和供应商等。 我现在需要将应用程序连接到第二个
我正在使用 2 个 Weblogic 数据源;在我的 XML 配置中,我有 2 个持久性单元、2 个 entityManagerFactories 和 2 个 transactionManagers。
从 JBoss 容器管理的 TransactionManagement 迁移到 Spring 管理的事务管理器 - (死)在插入表时锁定表并且不关闭 txn/session 并且从应用程序跟踪 txn
我使用 Spring Initializer、嵌入式 Tomcat、Thymeleaf 模板引擎生成了一个 Spring Boot Web 应用程序,并将其打包为可执行 JAR 文件。当我以正常模式运
我是一名优秀的程序员,十分优秀!