gpt4 book ai didi

java - 覆盖 spring batch admin 以使用 mysql 数据库

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:55:49 25 4
gpt4 key购买 nike

我正在尝试在 spring batch admin 中使用 mysql 数据库而不是默认的 HSQL。为此,根据文档

http://docs.spring.io/spring-batch-admin/reference/reference.xhtmlUsing jndi datasource with spring batch admin

我将 env-context.xml 复制到 src/main/resources/META-INF/batch/override/manager/env-context.xml 并更改了它的配置值(value)来自

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

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

下面是我的完整配置。

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

我还尝试将 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>

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

最佳答案

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

关于java - 覆盖 spring batch admin 以使用 mysql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22534032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com