Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-78134

When you enable separate read/write data sources in portal-ext.properties, a "cannot resolve reference to bean 'transactionAttributeSource' " error is thrown

    Details

      Description

      If you want to enable separate read/write data sources, you have to uncomment dynamic-data-source-spring.xml line in portal-ext.properties.
      More information, see: https://dev.liferay.com/discover/deployment/-/knowledge_base/7-0/liferay-clustering#read-writer-database-configuration

      But from Liferay 7 version, a "cannot resolve reference to bean 'transactionAttributeSource' " error is thrown after enabling that spring xml file.

      The root cause of this issue is LPS-54649. All spring configuration files where divided in two groups: spring.infrastructure.configs and spring.configs

      dynamic-data-source-spring.xml is included in spring.infrastructure.configs group, but it has a lot of dependencies with beans in spring.configs

      Steps to reproduce

      1. Configure a new Liferay installation using a database, for example mysql:
        jdbc.default.driverClassName=com.mysql.jdbc.Driver
        jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
        jdbc.default.username=your-db-user
        jdbc.default.password=your-db-password
        
      2. Start Liferay and verify database tables were created
      3. Stop Liferay in order to configure read/write setup
      4. Copy spring and spring.infrastructure section from portal.properties file to your portal-ext.properties:
        • Before the changes of this LPS: portal.properties
        • After the changes of this LPS: portal.properties
        • (You can also get the portal.properties directly from the portal-impl.jar of your Liferay installation)
      5. Uncomment dynamic-data-source-spring.xml lines. Important: After the changes of this LPS you will see two lines:
        • dynamic-data-source-spring.xml
        • dynamic-data-source-infrastructure-spring.xml
      6. Add jdbc.read. and jdbc.write. properties, pointing to same database than jdbc.default.. They should be different databases with replication, but for this issue it is not necessary to setup all that infrastructure.
        jdbc.read.driverClassName=com.mysql.jdbc.Driver
        jdbc.read.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
        jdbc.read.username=your-db-user
        jdbc.read.password=your-db-password
        jdbc.write.driverClassName=com.mysql.jdbc.Driver
        jdbc.write.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
        jdbc.write.username=your-db-user
        jdbc.write.password=your-db-password
        
      7. Comment jdbc.default properties added in step 1
      8. Add following lines:
        counter.jdbc.prefix=jdbc.write.
        jdbc.default.liferay.pool.provider=dbcp
      9. With read/write setup, "default" dataSource won't be used by Liferay, but jdbc driver will try connecting due to 'jdbc.default.validationQuery' configuration (it was added in LPS-64624). Add following lines to avoid jdbc driver connecting to "default" data source:
        jdbc.default.validationQuery=
        jdbc.read.validationQuery=SELECT releaseId FROM Release_
        jdbc.write.validationQuery=SELECT releaseId FROM Release_
        
      10. Start Liferay
        • Expected behavior: Liferay starts successfully
        • Wrong behavior: Following error is thrown in log file
          com.liferay.portal.spring.context.PortalContextLoaderListener
           java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dynamicDataSourceAdvice' defined in class path resource [META-INF/dynamic-data-source-spring.xml]: Cannot resolve reference to bean 'transactionAttributeSource' while setting bean property 'transactionAttributeSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionAttributeSource' is defined
          	at com.liferay.portal.spring.context.PortalContextLoaderListener.contextInitialized(PortalContextLoaderListener.java:260)
          	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4812)
          	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)
          	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
          	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
          	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
          	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
          	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:585)
          	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1794)
          	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
          	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
          	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
          	at java.lang.Thread.run(Thread.java:748)
          

      Note: You have more information about configuring this in https://dev.liferay.com/discover/deployment/-/knowledge_base/7-0/liferay-clustering#read-writer-database-configuration

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  1 year, 39 weeks, 3 days ago

                  Packages

                  Version Package
                  7.0.0 DXP FP40
                  7.0.0 DXP SP7
                  7.0.5 CE GA6
                  7.0.X
                  7.1.0 M2
                  7.1.X
                  Master