Premise : i'm new to spring batch.
I'm trying to customize the spring batch admin but , till now, i'm not been able to let my classes read some properties from an external file .
My jobs extract data from a third party database to print a report , therefore i need two datasource : one to gather the report information and one to store the job's status and metadata.
I've read the tutorial : http://docs.spring.io/spring-batch-admin/reference/customization.html
and many other tutorials and the following post load external config file in spring batch admin .
Yet i'm not been able to start the application .
It must run on Tomcat 6 .
this is a screen shoot of my project tree, adapted by the official example :
this is my configuration class :
@Configuration
@EnableBatchProcessing
public class RegistroGiornalieroConfiguration extends DefaultBatchConfigurer {
private final static Logger log = LoggerFactory.getLogger(RegistroGiornalieroConfiguration.class);
private final static Date data = null;
@Autowired
public JobBuilderFactory jobFactory;
@Autowired
public StepBuilderFactory stepFactory;
@Autowired
VolumiPropertySource volumiPropertySource;
@Value("${batch.jdbc.driver}")
private String driverName;
/**
* datasource di default, viene resitituito dall'annotazione Autowired
* @return
* @throws SQLException
*/
@Bean(name="springBatchDatasource")
@Primary
public DataSource springBatchDatasource() throws SQLException {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driverName);//"com.mysql.jdbc.Driver");
// dataSource.setUrl(env.getProperty("springBatchUrl"));//"jdbc:mysql://localhost/spring_batch_annotations");
// dataSource.setUsername(env.getProperty("springBatchUser"));//"root");
// dataSource.setPassword(env.getProperty("springBatchPassword"));//"root");
return dataSource;
}
/**
* Datasource secondario, viene restituito da getDatasource
* @return
* @throws SQLException
*/
@Bean(name="estarDatasource")
public DataSource estarDatasource() throws SQLException {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driverName);//"com.mysql.jdbc.Driver");
// dataSource.setUrl(env.getProperty("url"));//"jdbc:mysql://localhost/spring_batch_annotations");
// dataSource.setUsername(env.getProperty("user"));//"root");
// dataSource.setPassword(env.getProperty("password"));//"root");
return dataSource;
}
// @PostConstruct
// public void init()
// {
// Properties p = volumiPropertySource.getIniProperties();
// MutablePropertySources sources = env.getPropertySources();
// sources.addFirst(new PropertiesPropertySource("volumi",p));
// env.getActiveProfiles();
// }
@Bean
@StepScope
public JdbcCursorItemReader<RegistroGiornaliero> reader(
@Value("#{jobParameters[data]}")
Date data)
{
System.out.println("reader");
// select protocol.nprotoc,protocol.dataprot,protocol.arrpar,protocol.numdoc,
// protocol.datadoc,protocol.OGGETTO,protocol.ANNULLATO,protocol.USERINS as protuser,
// protimg.DOCID,protimg.USERINS imguser ,protimg.PRINCIPALE,
// assegna.livello,assegna.possesso,assegna.SEQUENZA,
// organigramma.LIVELLO,organigramma.DESCRIZIONE,
// protente.ente
// from
// protocol left outer join protimg on protocol.NPROTOC = protimg.NPROTOC
// left outer join protente on protocol.NPROTOC = protente.NPROTOC
// left outer join assegna on protocol.NPROTOC = assegna.NPROTOC
// left outer join organigramma on assegna.LIVELLO = organigramma.LIVELLO
// where
// protocol.dataprot = 20160616 and protocol.NPROTOC = '201600014709'
// order by protocol.nprotoc,assegna.SEQUENZA;
StringBuilder sb = new StringBuilder("select")
.append(" protocol.nprotoc,protocol.dataprot,protocol.arrpar,protocol.numdoc,")
.append(" protocol.datadoc,protocol.OGGETTO,protocol.ANNULLATO,protocol.USERINS as protuser,")
.append(" protimg.DOCID,protimg.USERINS imguser ,protimg.PRINCIPALE,")
.append(" assegna.possesso,assegna.SEQUENZA,")
.append(" organigramma.LIVELLO,organigramma.DESCRIZIONE,")
.append(" protente.ente ")
.append(" from protocol left outer join protimg on protocol.NPROTOC = protimg.NPROTOC ")
.append(" left outer join protente on protocol.NPROTOC = protente.NPROTOC ")
.append(" left outer join assegna on protocol.NPROTOC = assegna.NPROTOC ")
.append(" left outer join organigramma on assegna.LIVELLO = organigramma.LIVELLO ")
.append(" where ")
.append(" protocol.dataprot = ? ")
.append(" order by protocol.nprotoc,assegna.SEQUENZA ");
// StringBuilder sb = new StringBuilder("select")
// .append(" protocol.nprotoc,protocol.dataprot,protocol.arrpar,protocol.numdoc,")
// .append(" protocol.datadoc,protocol.OGGETTO,protocol.ANNULLATO,protocol.USERINS as protuser, ")
// .append(" protimg.DOCID,protimg.USERINS imguser ,protimg.PRINCIPALE, ")
// .append(" assegna.livello,assegna.possesso,assegna.SEQUENZA, ")
// .append(" organigramma.LIVELLO as livelloOrg,organigramma.DESCRIZIONE, ")
// .append(" protente.ente ")
// .append(" from protocol,protimg,protente,assegna,operatori,organigramma ")
// .append(" where ")
// .append(" protocol.NPROTOC = protimg.NPROTOC and protocol.NPROTOC = assegna.NPROTOC ")
// .append(" and protocol.NPROTOC = protente.NPROTOC and assegna.LIVELLO = organigramma.LIVELLO ")
// .append(" and protocol.dataprot = ? ");
JdbcCursorItemReader<RegistroGiornaliero> reader = new JdbcCursorItemReader<RegistroGiornaliero>();
try {
reader.setDataSource(estarDatasource());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
reader.setPreparedStatementSetter(new ParameterSetter(data));
reader.setSql(sb.toString());
reader.setRowMapper(estarRowMapper());
reader.setVerifyCursorPosition(false);
return reader;
}
@Bean
public RegistroGiornalieroProcessor processorGenerazioneRegistro() {
return new RegistroGiornalieroProcessor();
}
@Bean
public ItemWriter<RegistroGiornaliero> pdfwriter() {
return new PDFItemWriter<RegistroGiornaliero>();
}
@Bean
public JobExecutionListener listener() {
return new JobCompletionNotificationListener();
}
@Bean
public RegistroGiornalieroRowMapper estarRowMapper() {
return new RegistroGiornalieroRowMapper();
}
@Bean
public Job generaRegistroGiornaliero()
{
return jobFactory
.get("generaRegistroGiornaliero")
.incrementer(new RunIdIncrementer())
.flow(leggiDocumentiProtocollo())
.end()
.build();
}
@Bean
public Step leggiDocumentiProtocollo()
{
return stepFactory.get("leggiDocumentiProtocollo")
.<RegistroGiornaliero, RegistroGiornaliero> chunk(10)
.reader(reader(data))
.processor(processorGenerazioneRegistro())
.writer(pdfwriter())
.build();
}
@Override
public JobRepository getJobRepository() {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
// use the autowired data source
try {
factory.setDataSource(springBatchDatasource());
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
factory.setTransactionManager(getTransactionManager());
try {
factory.afterPropertiesSet();
return factory.getObject();
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
return null;
}
}
this is my job configuration (registrogiornaliero.xml):
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="it.infogroup.estav.registrogiornaliero"/>
</beans>
and finally this is my env.xml , as by stackoverflow post :
<?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-${ENVIRONMENT:hsql}.properties</value>-->
<value>classpath:batch-${ENVIRONMENT:mysql}.properties</value>
<!-- here we load properties from external config folder -->
<value>file:${app.conf}</value>
</list>
</property>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="false" />
<property name="ignoreUnresolvablePlaceholders" value="false" />
<property name="order" value="1" />
</bean>
</beans>
any help will be appreciated