Liferay Portal Version: liferay-dxp-digital-enterprise-7.0-sp3

Mysql version : Docker构建读写主从集群 (请看之前的文章)


在 Liferay DXP配置数据库读写分离的时候和Liferay 6.2有些不同.

1.配置数据源

jdbc.read.driverClassName=com.mysql.jdbc.Driver
jdbc.read.url=jdbc:mysql://localhost:23306/lportal_sales_portal?characterEncoding=UTF-8&dontTrackOpenResources=true&holdResultsOpenOverStatementClose=true&useFastDateParsing=false&useUnicode=true
jdbc.read.username=root
jdbc.read.password=000000

jdbc.write.driverClassName=com.mysql.jdbc.Driver
jdbc.write.url=jdbc:mysql://localhost:13306/lportal_sales_portal?characterEncoding=UTF-8&dontTrackOpenResources=true&holdResultsOpenOverStatementClose=true&useFastDateParsing=false&useUnicode=true
jdbc.write.username=root
jdbc.write.password=000000

2.编写配置文件

在目录{bundle}\tomcat-8.0.32\webapps\ROOT\WEB-INF\classes\META-INF中创建文件infrastructure-spring-ext.xml, 文件是拷贝来自原liferay infrastructure-spring.xml 文件.但是移除了数据源的配置.

<?xml version="1.0"?>

<beans
    default-destroy-method="destroy"
    default-init-method="afterPropertiesSet"
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
>
    <bean class="com.liferay.mail.util.MailSessionFactoryBean" id="mailSession">
        <property name="propertyPrefix" value="mail.session." />
    </bean>
    <bean class="com.liferay.portal.service.PersistedModelLocalServiceRegistryImpl" id="com.liferay.portal.kernel.service.PersistedModelLocalServiceRegistry" />
    <bean class="com.liferay.portal.kernel.service.PersistedModelLocalServiceRegistryUtil" id="com.liferay.portal.kernel.service.PersistedModelLocalServiceRegistryUtil">
        <property name="persistedModelLocalServiceRegistry" ref="com.liferay.portal.kernel.service.PersistedModelLocalServiceRegistry" />
    </bean>
    <bean class="com.liferay.portal.kernel.util.InfrastructureUtil" id="com.liferay.portal.kernel.util.InfrastructureUtil">
        <property name="dataSource" ref="liferayDataSource" />
        <property name="mailSession" ref="mailSession" />
        <property name="transactionManager" ref="liferayTransactionManager" />
    </bean>
</beans>

3.编写配置portal-ext 文件

spring.configs=\
    META-INF/base-spring.xml,\
    \
    META-INF/util-spring.xml,\
    \
    META-INF/executor-spring.xml,\
    META-INF/fabric-spring.xml,\
    \
    META-INF/messaging-core-spring.xml,\
    META-INF/messaging-misc-spring.xml,\
    \
    META-INF/asset-spring.xml,\
    META-INF/cluster-spring.xml,\
    META-INF/comment-spring.xml,\
    META-INF/company-provider-spring.xml,\
    META-INF/document-library-spring.xml,\
    META-INF/layout-spring.xml,\
    META-INF/message-boards-spring.xml,\
    META-INF/model-listener-spring.xml,\
    META-INF/notifications-spring.xml,\
    META-INF/poller-spring.xml,\
    META-INF/prefs-spring.xml,\
    META-INF/repository-spring.xml,\
    META-INF/search-spring.xml,\
    META-INF/security-spring.xml,\
    META-INF/service-configurator-spring.xml,\
    META-INF/social-spring.xml,\
    META-INF/workflow-spring.xml,\
    \
    META-INF/counter-spring.xml,\
    META-INF/mail-spring.xml,\
    META-INF/portal-spring.xml,\
    META-INF/portlet-container-spring.xml,\
    META-INF/staging-spring.xml,\
    META-INF/virtual-layouts-spring.xml,\
    \
    META-INF/monitoring-spring.xml,\
    \
    META-INF/dynamic-data-source-spring.xml,\
    \
    classpath*:META-INF/ext-spring.xml

#
# Input a list of comma delimited Spring infrastructure configurations.
# These will be loaded after the module framework is initialized but
# before it is started.
#
spring.infrastructure.configs=\
    META-INF/base-spring.xml,\
    \
    META-INF/hibernate-spring.xml,\
    \
    META-INF/counter-infrastructure-spring.xml,\
    \
    META-INF/dynamic-data-source-spring.xml,\
    \
    META-INF/infrastructure-spring-ext.xml

counter.jdbc.prefix=jdbc.write.

4.重启服务器, 齐活,