Removing duplicate code from Spring job configuration - java

Below is my step configuration -
<beans:bean id="myInputFileReader" class="com.rbos.fm.risk.batch.spring.reader.InputFileReader" scope="step">
<beans:property name="delegate">
<beans:bean class="org.springframework.batch.item.file.FlatFileItemReader"
scope="step">
<beans:property name="resource" ref="inputFileSystemResource" />
<beans:property name="linesToSkip" value="1" />
<beans:property name="lineMapper">
<beans:bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<beans:property name="lineTokenizer">
<beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<beans:property name="delimiter" value="|"/>
</beans:bean>
</beans:property>
<beans:property name="fieldSetMapper">
<beans:bean class="com.test.MyFieldMapper1" scope="prototype"/>
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
</beans:property>
<beans:property name="param1" value="#{jobParameters['param1']}"/>
<beans:property name="param2" value="#{jobParameters['param2']}"/>
<beans:property name="param3" value="#{jobParameters['param3']}"/>
</beans:bean>
<beans:bean id="fileItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
<beans:property name="resource" ref="outputFileSystemResource" />
<beans:property name="lineAggregator">
<beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
<beans:property name="delimiter" value="|"/>
<beans:property name="fieldExtractor">
<beans:bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
<beans:property name="names"
value="outcolomn1, outcolomn2, outcolomn3, outcolomn4"/>
</beans:bean>
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
<step id="myPreProcessing1">
<tasklet>
<chunk reader="myInputFileReader" processor="myFileProcessor1" writer="fileItemWriter"
commit-interval="10000"/>
</tasklet>
</step>
I have to add other (similar) steps. I would like to use same readers and writers as only change in reader will be a new FieldSetMapper and writer will be a new BeanWrapperFieldExtractor. So ideally, I would like to specify a reader and writer on parent level and would like to refer them in all the steps by just overriding new mapper and extractor.

Use Bean Definition Inheritance. Create an abstract bean definition and have your actual definitions use this as a parent.
<beans:bean id="parentInputFileReader" class="com.rbos.fm.risk.batch.spring.reader.InputFileReader" scope="step" abstract="true">
<beans:property name="delegate">
<beans:bean class="org.springframework.batch.item.file.FlatFileItemReader">
<beans:property name="resource" ref="inputFileSystemResource" />
<beans:property name="linesToSkip" value="1" />
</beans:bean>
</beans:property>
<beans:property name="param1" value="#{jobParameters['param1']}"/>
<beans:property name="param2" value="#{jobParameters['param2']}"/>
<beans:property name="param3" value="#{jobParameters['param3']}"/>
</beans:bean>
<beans:bean id="parentLineMapper" class="org.springframework.batch.item.file.mapping.DefaultLineMapper" abstract="true">
<beans:property name="lineTokenizer">
<beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<beans:property name="delimiter" value="|"/>
</beans:bean>
</beans:property>
</beans:bean>
Now that you have parent beans you can reference them using the parent attribute and only configure those properties that are needed or need to be modified from the default.
<bean id="myInputFileReader" parent="parent">
<beans:property name="lineMapper">
<bean parent="parentLineMapper" >
<beans:property name="fieldSetMapper">
<beans:bean class="com.test.MyFieldMapper1" />
</beans:property>
</bean>
</beans:property />
</bean>

Related

Spring mvc mapping problems

I'm using spring mvc hibernate for a project.
Now i'm stuck on my mapping.
The normal url is:
localhost:8080/Carre2/......
Somepages have some parameters like
localhost:8080/Carre2/addproduct/edit/1
When i want to go to antoher page he request this:
localhost:8080/Carre2/addproduct/edit/home
I have no idea how to fix this mapping problem.
Someone can help?
Some code:
public class AddproductController {
private ProductService productService;
#Autowired(required = true)
#Qualifier(value = "productService")
public void setProductService(ProductService ps) {
this.productService = ps;
}
#RequestMapping(value = "/addproduct", method = RequestMethod.GET)
public String listProduct(Model model) {
model.addAttribute("product", new Product());
model.addAttribute("listProduct", this.productService.listProduct());
return "addproduct";
}
//For add and update person both
#RequestMapping(value = "/addproduct/add", method = RequestMethod.POST)
public String addProduct(#ModelAttribute("product") Product p) {
if (p.getId() == 0) {
//new person, add it
this.productService.addProduct(p);
} else {
//existing person, call update
this.productService.updateProduct(p);
}
return "redirect:/addproduct";
}
#RequestMapping("addproduct/update/{id}")
public String updateProduct(#PathVariable("id") int id, Model model) {
model.addAttribute("product", this.productService.getProductById(id));
model.addAttribute("listProduct", this.productService.listProduct());
return "productlist";
}
#RequestMapping("addproduct/edit/{id}")
public String editProduct(#PathVariable("id") int id, Model model) {
model.addAttribute("product", this.productService.getProductById(id));
model.addAttribute("listProduct", this.productService.listProduct());
return "addproduct";
}
Here my servlet-context.xml
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Resolves views selected for rendering by #Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<resources mapping="/resources/**" location="/resources/carre/" cache-period="31556926"/>
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url"
value="jdbc:mysql://localhost:3306/carre" />
<beans:property name="username" value="root" />
<beans:property name="password" value="...." />
</beans:bean>
<!-- Hibernate 4 SessionFactory Bean definition -->
<beans:bean id="hibernate4AnnotatedSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="annotatedClasses">
<beans:list>
<beans:value>com.carre.model.Person</beans:value>
<beans:value>com.carre.model.Product</beans:value>
<beans:value>com.carre.model.Categorie</beans:value>
<beans:value>com.carre.model.Catalogus</beans:value>
<beans:value>com.carre.model.Voorstelling</beans:value>
</beans:list>
</beans:property>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
</beans:prop>
<beans:prop key="hibernate.show_sql">true</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
<beans:bean id="catalogusDAO" class="com.carre.dao.CatalogusDAOImpl">
<beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="CatalogusService" class="com.carre.service.CatalogusServiceImpl">
<beans:property name="catalogusDAO" ref="catalogusDAO"></beans:property>
</beans:bean>
<beans:bean id="personDAO" class="com.carre.dao.PersonDAOImpl">
<beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="personService" class="com.carre.service.PersonServiceImpl">
<beans:property name="personDAO" ref="personDAO"></beans:property>
</beans:bean>
<beans:bean id="productDAO" class="com.carre.dao.ProductDAOImpl">
<beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="productService" class="com.carre.service.ProductServiceImpl">
<beans:property name="productDAO" ref="productDAO"></beans:property>
</beans:bean>
<beans:bean id="categorieDAO" class="com.carre.dao.CategorieDAOImpl">
<beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="CategorieService" class="com.carre.service.CategorieServiceImpl">
<beans:property name="categorieDAO" ref="categorieDAO"></beans:property>
</beans:bean>
<beans:bean id="voorstellingDAO" class="com.carre.dao.VoorstellingDAOImpl">
<beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
<beans:bean id="VoorstellingService" class="com.carre.service.VoorstellingServiceImpl">
<beans:property name="voorstellingDAO" ref="voorstellingDAO"></beans:property>
</beans:bean>
<context:component-scan base-package="com.carre.controller" />
<tx:annotation-driven transaction-manager="transactionManager"/>
<beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
Here is how i want to get to the url.
c:url value='addproduct/edit/${product.id}'
I would recommend to use c:url like as below to fix it:
c:url value="${pageContext.request.contextPath}/addproduct/edit/${product.id}"
Basically try to take ${pageContext.request.contextPath} for each c:url
It will converted into "localhost:8080/Carre2"
You just need to access it as follows,
c:url value='/addproduct/edit/${product.id}'
This will make the url to start from your context path.
Or better way could be to store the context path globally and use it in each url. You can refer to context path as follows,
c:url value="${pageContext.request.contextPath}/addproduct/edit/${product.id}"

Spring-Batch Invalid JobExecution, ID not found

I am trying to run few spring-batch jobs in a loop. Some of the jobs gets successfully completed. But others do not , and the below exception is thrown in the logs:
<ERROR> [org.springframework.batch.core.job.AbstractJob] :Encountered fatal error executing job
org.springframework.batch.core.repository.dao.NoSuchObjectException: **Invalid JobExecution, ID <theid> not found.**
at org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.updateJobExecution(JdbcJobExecutionDao.java:197)
at
The applicationContext.xml has the below configurations:
<beans:bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<beans:property name="databaseType" value="POSTGRES" />
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="transactionManager" ref="transactionManager" />
<beans:property name="isolationLevelForCreate" value="ISOLATION_DEFAULT" />
</beans:bean>
<beans:bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<beans:property name="jobRepository" ref="jobRepository" />
</beans:bean>
<beans:bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
</beans:bean>
<beans:bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<beans:property name="dataSource"
ref="dataSource" />
</beans:bean>

dificullty while using two databases in the spring hibernate application

I am trying to use 2 databases in my spring project. It is working fine if I use 1 database but when add other databases I am getting following error message.
org.hibernate.HibernateException: No Session found for current thread
dispatcher-servlet
<beans:bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="sample" />
<beans:property name="annotatedClasses">
<beans:list>
<beans:value>com.kendoui.spring.models.Constraint</beans:value>
</beans:list>
</beans:property>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect
</beans:prop>
<beans:prop key="hibernate.show_sql">true</beans:prop>
<beans:prop key="hibernate.format_sql">true</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
<beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory" />
</beans:bean>
<beans:bean id="Ascent" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<beans:property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<beans:property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=Ascent;" />
<beans:property name="username" value="sa" />
<beans:property name="password" value="abc123" />
<beans:property name="maxActive" value="1" />
<beans:property name="maxIdle" value="1" />
</beans:bean>
<beans:bean id="sessionFactory2" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="Ascent" />
<beans:property name="annotatedClasses">
<beans:list>
<beans:value>com.kendoui.spring.models.ItemOperationSequence</beans:value>
</beans:list>
</beans:property>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</beans:prop>
<beans:prop key="hibernate.show_sql">true</beans:prop>
<beans:prop key="hibernate.format_sql">true</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
<beans:bean id="transactionManager2" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory2" />
</beans:bean>
<!-- Enable annotation driven transactions. Required by getCurrentSession(). -->
<tx:annotation-driven/>
DAO implemantation
#Transactional("transactionManager2")
#Component
public class ItemOprSeqDaoImpl implements ItemOprSeqDao {
#Autowired
private SessionFactory sessionFactory;
#Override
public List<ItemOperationSequence> getList(String Itemcode) {
Session session = sessionFactory.getCurrentSession();
String queryStr= "select * from [#is_itemtrvoprdetails]";
Query query= session.createSQLQuery(queryStr).addEntity(ItemOperationSequence.class);
List <ItemOperationSequence> d=query.list();
return d;
}
}
I tried many different things but it is not working.
I tried using <beans:qualifier value="Ascent" /> in my servlet
and
#Qualifier(value="SessionFactory2") in my DAO
but nothing seems to work.
Anyone knows the answer to this problem. I would really appreciate if you could help.
Thanks in advance.
<tx:annotation-driven/> should be declared twice once for each transaction manager.
<tx:annotation-driven transaction-manager="transactionManager2"/>
and
<tx:annotation-driven transaction-manager="transactionManager"/>
Also add #Qualifier for
#Autowired
#Qualifier(value="SessionFactory2")
private SessionFactory sessionFactory;
You need to define a ChainedTransactionManager with both HibernateTransactionManagers as input.
I am not used to spring xml configuration, but it should look like this.
Than just use only #Transactional without a value.
<beans:bean id="transactionManager1" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory" />
</beans:bean>
<beans:bean id="transactionManager2" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory2" />
</beans:bean>
<beans:bean id="transactionManager" class="org.springframework.data.transaction.ChainedTransactionManager">
<beans:constructor-arg>
<list>
<beans:ref bean="transactionManager1" />
<beans:ref bean="transactionManager2" />
</list>
</beans:constructor-arg>
</beans:bean>
Okay I solved the problem by doing this.
first declared transaction-manager
<tx:annotation-driven transaction-manager="transactionManager1"/>
Then in my DAO used
#Transactional("transactionManager2")
#Component
public class ItemOprSeqDaoImpl implements ItemOprSeqDao {
#Autowired
#Qualifier("sessionFactory2")
private SessionFactory sessionFactory;
//then rest of the code
}
Its working fine now. Thanks you guys for your help.

Migrating from spring 3 to 4

I have a code snippet
<beans:bean id="accessDecisionManager"
class="org.springframework.security.access.vote.AffirmativeBased">
<beans:property name="decisionVoters">
<beans:list>
<beans:bean
class="org.springframework.security.access.vote.AuthenticatedVoter" />
<beans:bean class="org.springframework.security.access.vote.RoleVoter" />
</beans:list>
</beans:property>
</beans:bean>
I want to migrate this to spring 4
According to http://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3-to-4-xml.html#m3to4-deprecations-core-aadm
I know that if i have something like this:
<b:bean class="org.springframework.security.access.vote.UnanimousBased">
<b:property name="decisionVoters" ref="voters"/>
</b:bean>
I have to do :
<b:bean class="org.springframework.security.access.vote.UnanimousBased">
<b:constructor-arg ref="voters"/>
</b:bean>
But i don't know how to do it in my case.. please help
I would also appreciate if you could point out the signifacance of property name thank you.
Sorry pretty stupid of me. This seems to work perfect.
<beans:bean id="accessDecisionManager"
class="org.springframework.security.access.vote.AffirmativeBased">
<beans:constructor-arg>
<beans:list>
<beans:bean
class="org.springframework.security.access.vote.AuthenticatedVoter" />
<beans:bean class="org.springframework.security.access.vote.RoleVoter" />
</beans:list>
</beans:constructor-arg>
</beans:bean>

Too many Connections Exception in Spring Batch

In my web application I am using Spring Batch Framework and mysql database. In DAO class I am closing all the connection but still I am getting "Too many Connections" Exception.Plz help how to resolve this.
This is my Spring Batch configuration files:
EramBatchJob.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/batch"
xmlns:beans="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-2.0.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="location">
<beans:value>eramBatchApp.properties</beans:value>
</beans:property>
</beans:bean>
<beans:import resource="EramGBT-JOBREPOSITORY.xml"/>
<!-- Headers -->
<beans:bean id="accountHeader" class="com.order.batch.AccountHeader" scope="step">
<beans:property name="seperator" value="#{jobParameters['Delimiter']}">
</beans:property>
</beans:bean>
<beans:bean id="customerHeader" class="com.order.batch.CustomerHeader" scope="step">
<beans:property name="seperator" value="#{jobParameters['Delimiter']}"></beans:property>
</beans:bean>
<beans:bean id="finstatHeader" class="com.order.batch.FinStatHeader" scope="step">
<beans:property name="seperator" value="#{jobParameters['Delimiter']}"></beans:property>
</beans:bean>
<!-- Headers -->
<!-- Asynchronous Executor -->
<beans:bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" scope="step">
<!-- <beans:property name="concurrencyLimit" value="5"/> -->
<beans:property name="concurrencyLimit" value="#{jobParameters['concurrencyLimit']}"/>
</beans:bean>
<!-- Reader -->
<beans:bean id="accountInfoFileReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<beans:property name="resource" value="file:#{jobParameters['resource']}" />
<beans:property name="lineMapper">
<beans:bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<beans:property name="lineTokenizer">
<beans:bean class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
<!-- <beans:property name="delimiter" value=" "/> -->
<!-- <beans:property name="columns" value="1-30,31-120,121-190,191-260,261-310,311-360,361-370,371-380,381-382,420-423,400-419,385-393,424-451" /> Correct -->
<!-- <beans:property name="columns" value="1-30,31-120,121-190,191-260,261-310,311-360,361-370,371-380,381-382,371-380,400-419,385-393,420-451" /> -->
<beans:property name="columns" value="#{jobParameters['InputDeLimiter']}" />
<beans:property name="names" value="accountNumber,businessName,addr1,addr2,city,state,zip,phone,countryCode,phoneCode,bizID,duns,dummy" />
</beans:bean>
</beans:property>
<beans:property name="fieldSetMapper">
<beans:bean class="com.order.batch.AccountInfoFiledSetMap" />
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
<!-- Processor -->
<beans:bean id="productOrderProccesor" class="com.order.batch.ProductOrderProccesor" scope="step">
<beans:property name="toolKitId" value="#{jobParameters['toolKitId']}"/>
<beans:property name="toolKitPwd" value="#{jobParameters['toolKitPwd']}"/>
</beans:bean>
<!-- Wrtiter -->
<!-- Account File Writer -->
<beans:bean id="accountFileWriter" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
<beans:property name="resource" value="file:#{jobParameters['AccountFilePath']}" />
<!-- <beans:property name="appendAllowed" value="true" />-->
<!--<beans:property name="shouldDeleteIfExists" value="true"/> -->
<beans:property name="lineAggregator">
<beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
<beans:property name="delimiter" value="#{jobParameters['Delimiter']}"/>
<!-- <beans:property name="columns" value="1-30,31-120,121-190,191-260,261-310,311-360,361-370,371-380,381-382,371-380,400-419,385-393,420-452" /> -->
<beans:property name="fieldExtractor">
<beans:bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
<beans:property name="names" value="sacct_Nbr_Cust,scountryCode_Cust,sCrcy_Cd,sDuns_Nbr,sEnq_Duns,sPrim_Name,sAddr_Line,sPost_Town,sPrim_Geo_Area,sPost_Cd,sCntry_Cd,sTlcm_Nbr,sCurr_Cntl_Yr,sTotl_Emp,sPrim_Sic,sLoc_Stat,sLgl_Form,sAddr_Tenr_Type_Cd,sCeo_Nme,sPayd_Scr,sPays_3_Mo_Ago,sPayd_Norm,sAvg_High_Cr,sHigh_Cr,sTot_Pmt,sFinl_Embt_Ind,sOut_Bus_In,sCrim_Ind,sHist_Ind,sImpt_Ind,sExpt_Ind,sDnb_Ratg,sRat_Cd,sAaa_Rat,sBus_Stru,sHq_Duns,sHq_Nme,sHq_Cntry_Cd,sPnt_Nme,sPnt_Duns,sPnt_Ctry_Cd,sDom_Ult_Pnt_Nme,sDom_Ult_Pnt_Duns,sDom_Ult_Ctry_Cd,sGbl_Ult_Pnt_Nme,sGbl_Ult_Pnt_Duns,sGbl_Ult_Ctry_Cd,sDelq_Scr_Entr_Natl_Pctl,sDelq_Scr_Entr_Inds_Pctl,sDelq_Scr_Entr_Inds_Defu_Indn,sFail_Scr_Entr_Natl_Pctl,sFail_Scr_Entr_Defu_Indn,sFail_Scr_Entr_Inds_Pctl,sFail_Scr_Entr_Inds_Defu_Indn,sCurr_Rato,sQk_Rato,sClm_Ind,sSuit_Jdgt_Ind,sTrdg_Styl,sTrdg_Styl1,sTrdg_Styl2,sTrdg_Styl3,sTrdg_Styl4,sPrim_Sic,sPrim_Sic_Type_Cd,sLcl_Atv_Cd,sLcl_Actv_Cd_Type,sStrt_Yr,sBus_Regn_Nbr,sMax_Cr,sIncn_Yr,sEu_Admin_App,sEu_Burgalary_Ind,sEu_Bus_Cease_Ind,sEu_Bus_Windup_Ind,sFire_Ind,sEu_Insol_Stmt,sEu_Liqd_It,sEu_Meet_Crdtr,sEu_Min_Dat_Ind,sEu_Misc_Ovrd,sEu_Neg_Inf_Ind,sFail_Scr_Entr_Scr_Cmty_Cd,sFail_Scr_Entr_Scr_Cmty_Cd1,sFail_Scr_Entr_Scr_Cmty_Cd2,sFail_Scr_Entr_Scr_Cmty_Cd3,sFail_Scr_Entr_Scr_Cmty_Cd4,sFail_Scr_Entr_Scr_Cmty_Cd5,sFail_Scr_Entr_Scr_Cmty_Cd6,sFail_Scr_Entr_Scr_Cmty_Cd7,sFail_Scr_Entr_Scr_Cmty_Cd8,sFail_Scr_Entr_Scr_Cmty_Cd9,sFail_Scr_Entr_Scr_Cmty_Cd10,sFail_Scr_Entr_Scr_Cmty_Cd11,sFail_Scr_Entr_Scr_Cmty_Cd12,sFail_Scr_Entr_Scr_Cmty_Cd13,sFail_Scr_Entr_Scr_Cmty_Cd14,sFail_Scr_Entr_Scr_Cmty_Cd15,sFail_Scr_Entr_Scr_Cmty_Cd16,sFail_Scr_Entr_Scr_Cmty_Cd17,sFail_Scr_Entr_Scr_Cmty_Cd18,sFail_Scr_Entr_Scr_Cmty_Cd19,sFail_Scr_Entr_Scr_Cmty_Cd20,sFail_Scr_Entr_Scr_Cmty_Cd21,sFail_Scr_Entr_Scr_Cmty_Cd22,sFail_Scr_Entr_Scr_Cmty_Cd23,sFail_Scr_Entr_Scr_Cmty_Cd24,sFail_Scr_Entr_Scr_Cmty_Cd25,sFail_Scr_Entr_Scr_Cmty_Cd26,sFail_Scr_Entr_Scr_Cmty_Cd27,sFail_Scr_Entr_Scr_Cmty_Cd28,sFail_Scr_Entr_Scr_Cmty_Cd29,sFail_Scr_Entr_Scr_Ovrd_Cd,sFail_Scr_Entr_Scr_Ovrd_Cd1,sFail_Scr_Entr_Scr_Ovrd_Cd2,sFail_Scr_Entr_Scr_Ovrd_Cd3,sFail_Scr_Entr_Scr_Ovrd_Cd4,sDelq_Scr_Entr_Scr_Cmty_Cd,sDelq_Scr_Entr_Scr_Cmty_Cd1,sDelq_Scr_Entr_Scr_Cmty_Cd2,sDelq_Scr_Entr_Scr_Cmty_Cd3,sDelq_Scr_Entr_Scr_Cmty_Cd4,sDelq_Scr_Entr_Scr_Cmty_Cd5,sDelq_Scr_Entr_Scr_Cmty_Cd6,sDelq_Scr_Entr_Scr_Cmty_Cd7,sDelq_Scr_Entr_Scr_Cmty_Cd8,sDelq_Scr_Entr_Scr_Cmty_Cd9,sDelq_Scr_Entr_Scr_Cmty_Cd10,sDelq_Scr_Entr_Scr_Cmty_Cd11,sDelq_Scr_Entr_Scr_Cmty_Cd12,sDelq_Scr_Entr_Scr_Cmty_Cd13,sDelq_Scr_Entr_Scr_Cmty_Cd14,sDelq_Scr_Scr_Ovrd_Cd,sDelq_Scr_Scr_Ovrd_Cd1,sDelq_Scr_Scr_Ovrd_Cd2,sDelq_Scr_Scr_Ovrd_Cd3,sDelq_Scr_Scr_Ovrd_Cd4,sDast_Ref_Dt,sRate_Id,sRpt_Net_Wrth,sRpt_Net_Sls,sRpt_Net_Income,sCustomer_Bs_Name,dummydelimiter"/>
</beans:bean>
</beans:property>
</beans:bean>
</beans:property>
<beans:property name="headerCallback" ref="accountHeader"></beans:property>
</beans:bean>
<!-- Customer File Writer -->
<beans:bean id="customerFileWriter" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
<beans:property name="resource" value="file:#{jobParameters['CustomerFilePath']}" />
<!-- <beans:property name="appendAllowed" value="true" /> -->
<!--<beans:property name="shouldDeleteIfExists" value="true"/> -->
<beans:property name="lineAggregator">
<beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
<beans:property name="delimiter" value="#{jobParameters['Delimiter']}"/>
<beans:property name="fieldExtractor">
<beans:bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
<beans:property name="names" value="sacct_Nbr_Cust,sbusiness_Nme_Cust,saddr1_Cust,saddr2_Cust,scity_Cust,sstate_Cust,szip_Cust,sphoneCode_Cust,sphone_Cust,scountryCode_Cust,sDuns_cust"/>
</beans:bean>
</beans:property>
</beans:bean>
</beans:property>
<beans:property name="headerCallback" ref="customerHeader"></beans:property>
</beans:bean>
<!-- Finance Statement Writer -->
<beans:bean id="financeStatFileWriter" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
<beans:property name="resource" value="file:#{jobParameters['FinStatFilePath']}" />
<!-- <beans:property name="appendAllowed" value="true" /> -->
<!-- <beans:property name="shouldDeleteIfExists" value="true"/> -->
<beans:property name="lineAggregator">
<beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
<beans:property name="delimiter" value="#{jobParameters['Delimiter']}"/>
<beans:property name="fieldExtractor">
<beans:bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
<beans:property name="names" value="sacct_Nbr_Cust,sDnb_Ind,sCash_Liq_Aset,sAct_Rec,sAct_Pay,sStk,sTot_Curr_Aset,sTot_Curr_Liab,sTot_Aset,sTot_Liab,sNet_Wrth,sItng_Aset,sSls,sNet_Incm,sStmt_Dt,sStmt_Type,sRate_Id,sStmt_Crcy_Cd,dummydelimiter"/>
</beans:bean>
</beans:property>
</beans:bean>
</beans:property>
<beans:property name="headerCallback" ref="finstatHeader"></beans:property>
</beans:bean>
<!-- Composite Writer -->
<beans:bean id="compositeWriter" class="org.springframework.batch.item.support.CompositeItemWriter">
<beans:property name="delegates">
<beans:list>
<beans:ref bean="accountFileWriter" />
<beans:ref bean="customerFileWriter" />
<beans:ref bean="financeStatFileWriter" />
</beans:list>
</beans:property>
</beans:bean>
<!-- Writers fro Skip Plocies -->
<beans:bean id="excludeWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
<beans:property name="shouldDeleteIfExists" value="true"/>
<beans:property name="lineAggregator">
<beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
<beans:property name="delimiter" value=","/>
<beans:property name="fieldExtractor">
<beans:bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
<beans:property name="names" value="errormessage,accountNumber,businessName,addr1,addr2,city,state,zip,phone,countryCode,phoneCode,bizID,duns"/>
</beans:bean>
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
<beans:bean id="writeWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
<beans:property name="shouldDeleteIfExists" value="true"/>
<beans:property name="lineAggregator">
<beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
<beans:property name="delimiter" value=","/>
<beans:property name="fieldExtractor">
<beans:bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
<beans:property name="names" value="sAcct_Nbr,sDuns_Nbr,sCustomer_Bs_Name"/>
</beans:bean>
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
<!-- Listeners -->
<beans:bean id="eramBatchListener" class="com.order.batch.EramJobListener">
<beans:property name="excludeWriter" ref="excludeWriter" ></beans:property>
<beans:property name="writeWriter" ref="writeWriter" ></beans:property>
</beans:bean>
<!-- Job -->
<job id="EramBatchJob" job-repository="jobRepository" >
<step id="step2">
<tasklet transaction-manager="jobRepository-transactionManager" task-executor="taskExecutor">
<chunk reader="accountInfoFileReader" processor="productOrderProccesor" writer="compositeWriter"
commit-interval="#{jobParameters['CommitInterval']}" skip-limit="10000" retry-limit="1">
<streams>
<stream ref="compositeWriter"/>
<stream ref="accountInfoFileReader"/>
<stream ref="excludeWriter"/>
<stream ref="writeWriter"/>
</streams>
<retryable-exception-classes>
<include class="java.lang.Exception"/>
</retryable-exception-classes>
<skippable-exception-classes>
<include class="org.springframework.batch.item.file.FlatFileParseException"/>
<include class="org.springframework.batch.item.file.transform.IncorrectLineLengthException"/>
<include class="org.springframework.batch.core.step.skip.NonSkippableReadException"/>
<include class="java.io.IOException"/>
<include class="org.springframework.beans.NotReadablePropertyException"/>
<include class="org.springframework.batch.item.ItemStreamException"/>
<include class="com.order.exception.InvalidDunsOrCountryCodeException"/>
</skippable-exception-classes>
<listeners>
<listener ref="eramBatchListener" />
</listeners>
</chunk>
</tasklet>
<listeners>
<listener ref="eramBatchListener"/>
</listeners>
</step>
<listeners>
<listener ref="eramBatchListener"/>
</listeners>
</job>
</beans:beans>
EramGBT-JOBREPOSITORY.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
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-2.0.xsd">
<bean id="jobRepository-dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${EramBatch.App.DataBase.DriverClass}" />
<property name="url" value="${EramBatch.App.DataBase.DataBaseURL}" />
<property name="username" value="${EramBatch.App.DataBase.UserName}" /> <!-- your user id. e.g. root-->
<property name="password" value="${EramBatch.App.DataBase.Password}" /> <!-- your password-->
<property name="maxIdle" value="10"/>
<property name="maxActive" value="100"/>
<property name="maxWait" value="10000"/>
<property name="validationQuery" value="select 1"/>
<property name="testOnBorrow" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1200000"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="5"/>
<property name="defaultAutoCommit" value="false"/>
</bean>
<bean id="jobRepository-transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init="true">
<property name="dataSource" ref="jobRepository-dataSource" />
</bean>
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="jobRepository-dataSource" />
<property name="transactionManager" ref="jobRepository-transactionManager"/>
<property name="isolationLevelForCreate" value="ISOLATION_READ_UNCOMMITTED" />
<property name="databaseType" value="mysql" />
<property name="tablePrefix" value="batch_"/>
</bean>
<bean id="asyncTaskExecutor"
class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository"/>
<property name="taskExecutor">
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
</property>
</bean>
<bean id="jobExplorer"
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"
p:dataSource-ref="jobRepository-dataSource" p:tablePrefix="batch_" />
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
<property name="jobExplorer" ref="jobExplorer"/>
<property name="jobRepository" ref="jobRepository"/>
<property name="jobRegistry" ref="jobRegistry" />
<property name="jobLauncher" ref="jobLauncher" />
</bean>
</beans>
This looks like a MySQL error. Try increasing max_connections in /etc/my.cnf.
Also you may look into your app's multiprocessing and threading model. Exhaustion of MySQL connections could indicate a problem where the application is spawning new threads/processes all the time.

Categories