Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

override spring batch admin to use mysql database

I am trying to use mysql database instead of default HSQL in spring batch admin. For that as per documentation

http://docs.spring.io/spring-batch-admin/reference/reference.xhtml and Using jndi datasource with spring batch admin

I copied env-context.xml to src/main/resources/META-INF/batch/override/manager/env-context.xml and changed its configuration value from

<value>classpath:batch-${ENVIRONMENT:hsql}.properties</value>

to

 <value>classpath:batch-mysql.properties</value>

Below is my full configuration.

<?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>

I also tried coping data-source-context.xml to same folder and changing its configurations to 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>

But it still using hsql database? How to override default configuration to use mysql database ?

like image 796
vishal Avatar asked Mar 20 '14 13:03

vishal


Video Answer


1 Answers

You shouldn't replace the <value>classpath:batch-${ENVIRONMENT:hsql}.properties</value>. Instead, pass in an environment variable ENVIRONMENT set to mysql. That should cause all the appropriate components to pick up the correct database. You can read more about that feature here: http://docs.spring.io/spring-batch-admin/reference/infrastructure.html#Environment_Settings

like image 70
Michael Minella Avatar answered Nov 04 '22 15:11

Michael Minella