覆盖spring批处理admin以使用mysql数据库

vis*_*hal 8 java spring spring-mvc spring-batch spring-batch-admin

我试图在spring batch admin中使用mysql数据库而不是默认的HSQL.对于那个文件

http://docs.spring.io/spring-batch-admin/reference/reference.xhtml使用jndi数据源与spring batch admin

我复制env-context.xmlsrc/main/resources/META-INF/batch/override/manager/env-context.xml 和改变其配置价值

<value>classpath:batch-${ENVIRONMENT:hsql}.properties</value>
Run Code Online (Sandbox Code Playgroud)

 <value>classpath:batch-mysql.properties</value>
Run Code Online (Sandbox Code Playgroud)

以下是我的完整配置.

<?xml version="1.0" encoding="UTF-8"?>
<beans 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.xsd">

    <!--  Use this to set additional properties on beans at run time -->
    <bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:/org/springframework/batch/admin/bootstrap/batch.properties</value>
                <value>classpath:batch-default.properties</value>
                <value>classpath:batch-mysql.properties</value>
            </list>
        </property>
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <property name="ignoreResourceNotFound" value="true" />
        <property name="ignoreUnresolvablePlaceholders" value="false" />
        <property name="order" value="1" />
    </bean>

</beans>
Run Code Online (Sandbox Code Playgroud)

我还尝试将data-source-context.xml复制到同一文件夹并将其配置更改为mysql

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost/batch" />
        <property name="username" value="root" />
        <property name="password" value="root" />
        <property name="testWhileIdle" value="true"/>
        <property name="validationQuery" value="SELECT 1"/>
    </bean>

    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!--  Initialise the database if enabled: -->
    <jdbc:initialize-database data-source="dataSource" enabled="false" ignore-failures="DROPS">
        <jdbc:script location="classpath*:/org/springframework/batch/core/schema-drop-mysql.sql"/>
        <jdbc:script location="classpath:/org/springframework/batch/core/schema-mysql.sql"/>
        <jdbc:script location="classpath:/business-schema-mysql.sql"/>
    </jdbc:initialize-database>

</beans>
Run Code Online (Sandbox Code Playgroud)

但它仍然使用hsql数据库?如何覆盖默认配置以使用mysql数据库?

Mic*_*lla 2

你不应该更换<value>classpath:batch-${ENVIRONMENT:hsql}.properties</value>. 相反,传入ENVIRONMENT设置为 mysql 的环境变量。这应该会导致所有适当的组件选择正确的数据库。您可以在此处阅读有关该功能的更多信息:http ://docs.spring.io/spring-batch-admin/reference/infrastruct.html#Environment_Settings