2012-04-05 11 views
5

Questo sembra essere un problema stupido. Sto cercando di configurare un database Oracle10g per Spring Batch Job Repository (Spring Batch 2.1.7), sono stato in grado di creare le tabelle utilizzando lo script disponibile su org/springframework/batch/core/schema-oracle10g.sql in nucleo. Ho anche impostato la proprietà batch.data.source.init a false.Il batch di primavera sta tentando di creare nuovamente un gruppo di oggetti batch persistente

Su un database pulito, il mio programma batch funziona correttamente, creando correttamente tutte le tabelle/sequenze batch e popolandole con i dettagli dei risultati batch. Tuttavia, quando lo eseguo di nuovo, Spring Batch tenta di creare nuovamente queste tabelle e lancia l'eccezione "ORA-00955: nome è già utilizzato da un oggetto esistente". Che cosa sto facendo di sbagliato?

# For Oracle 
batch.jdbc.driver=oracle.jdbc.driver.OracleDriver 
batch.jdbc.url=jdbc:oracle:thin:@localhost:1521:orcl 
batch.jdbc.user=**** 
batch.jdbc.password=**** 
batch.schema=**** 
batch.schema.script=classpath:/org/springframework/batch/core/schema-oracle10g.sql 
batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-oracle10g.sql 
batch.jdbc.testWhileIdle=true 
batch.data.source.init=false 

seguito è il mio file di contesto:

<?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:batch="http://www.springframework.org/schema/batch" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd 
     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-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <context:property-placeholder location="classpath:batch.properties" /> 

    <context:component-scan base-package="com.myco.mypack" /> 

    <jdbc:initialize-database data-source="dataSource"> 
     <jdbc:script location="${batch.schema.script}" /> 
    </jdbc:initialize-database> 

    <import resource="classpath:/META-INF/spring/module-context.xml" /> 

    <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> 
     <property name="jobRepository" ref="jobRepository"/> 
    </bean> 

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

    <bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="transactionManager" ref="transactionManager"/> 
     <property name="databaseType" value="oracle" /> 
     <property name="tablePrefix" value="BATCH_"/> 
     <property name="isolationLevelForCreate" value="ISOLATION_DEFAULT"/> 
    </bean> 

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
     destroy-method="close"> 
     <property name="driverClassName" value="${batch.jdbc.driver}" /> 
     <property name="url" value="${batch.jdbc.url}" /> 
     <property name="username" value="${batch.jdbc.user}" /> 
     <property name="password" value="${batch.jdbc.password}" /> 
    </bean> 
</beans> 
+0

per favore aggiungi la configurazione xml dove usi il segnaposto –

+0

Ciao Michael, ho modificato la mia domanda per aggiungere la configurazione XML. – dchucks

risposta

4

non vedo l'uso di batch.data.source.init come questo:

<jdbc:initialize-database data-source="dataSource" 
          enabled="${batch.data.source.init}"> 
    <jdbc:script location="${batch.schema.script}" /> 
</jdbc:initialize-database> 
+0

Grazie Michael, avevo provato a rimuovere anche questo dal mio XML ma non funzionava prima, ora funziona. Anche con l'attributo "enabled" impostato su false come suggerito. Non sono sicuro però perché il file batch.data.source.init non funzioni. – dchucks

+0

E potrebbe essere Michael, posso indurti a rispondere a un'altra banale domanda per principianti su Spring Batch. Possiamo creare un nuovo lavoro (pianificare un lavoro) o cancellarne uno esistente tramite l'amministratore di Spring Batch (vedo che la guida parla del caricamento di un XML per aggiungere un lavoro ma che sembra noioso, se esiste un'API perché non dovrebbe siamo in grado di creare un lavoro al volo attraverso l'interfaccia utente Web di Batch Admin)? – dchucks

+0

per favore aggiungi questo come una nuova domanda in modo che gli altri possano trovarlo anche :-) per il mio io posso dire - non so amministratore di batch di primavera abbastanza buono –

0
<jdbc:initialize-database data-source="dataSource" 
         enabled="${batch.data.source.init}"> 
<jdbc:script location="${batch.schema.script}" /> 

Se passo l'argomento della riga di comando -Dbatch.data.source.init = false, l'intializzazione non è abilitata.

Ma se io uso la configurazione qui sotto e set di permesso di falso nel contesto xml, quindi l'inizializzazione viene attivato anche se la bandiera enabled è falso

<jdbc:initialize-database data-source="dataSource" 
         enabled="false"> 
<jdbc:script location="false" /> 

3

E 'stato un po', ma credo che per persone alla ricerca di questo problema sarà utile sapere che è possibile disattivare la creazione dei database utilizzando

spring.batch.initializer.enabled=false 

in application.properties come indicato in t he documentazione: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html

+0

Grazie per questo.Si è verificato un problema con l'avvio dell'applicazione non riuscita a non essere in grado di eseguire SET TRANSACTION anche se non avevo codice DB. È venuto fuori a causa degli script sql predefiniti – canadiancreed

Problemi correlati