Mybatis configuration with typeAliases - spring

I'm developing a Java EE application based on Mybatis 3.0.5, Mybatis-spring 1.0.1 and Spring 3.0.5.RELEASE and I've found a problem using Alias in mybatis-config.xml. The trace is:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Invocation of init method failed; nested exception is org.springframework.core.NestedIOException:
Failed to parse config resource: class path resource [mybatis-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException:
Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException:
Error registering typeAlias for 'accesoUsuario'. Cause: java.lang.ClassNotFoundException:
Cannot find class: [PACKAGE OMITTED BY ME].AccesoUsuario
How can I resolve this problem?
This is my mybatis-config.xml (MYPACKAGE = es.my.package).
<settings>
<setting name="lazyLoadingEnabled" value="false" />
</settings>
<typeAliases>
<typeAlias alias="accesoUsuario" type="MYPACKAGE.persistencia.entidades.AccesoUsuario" />
<typeAlias alias="agrupacion" type="MYPACKAGE.persistencia.entidades.Agrupacion" />
<typeAlias alias="consulta" type="MYPACKAGE.persistencia.entidades.Consulta" />
<typeAlias alias="consultaDim" type="MYPACKAGE.persistencia.entidades.ConsultaDim" />
<typeAlias alias="consultaFiltro" type="MYPACKAGE.persistencia.entidades.ConsultaFiltro" />
<typeAlias alias="dato" type="MYPACKAGE.persistencia.entidades.Dato" />
<typeAlias alias="dimension" type="MYPACKAGE.persistencia.entidades.Dimension" />
<typeAlias alias="dominio" type="MYPACKAGE.persistencia.entidades.Dominio" />
<typeAlias alias="dominioDep" type="MYPACKAGE.persistencia.entidades.DominioDep" />
<typeAlias alias="entidad" type="MYPACKAGE.persistencia.entidades.Entidad" />
<typeAlias alias="error" type="MYPACKAGE.persistencia.entidades.ErrorProceso" />
<typeAlias alias="informe" type="MYPACKAGE.persistencia.entidades.Informe" />
<typeAlias alias="informeCabecera" type="MYPACKAGE.persistencia.entidades.InformeCabecera" />
<typeAlias alias="informeSeccion" type="MYPACKAGE.persistencia.entidades.InformeSeccion" />
<typeAlias alias="restriVariable" type="MYPACKAGE.persistencia.entidades.RestriVariable" />
<typeAlias alias="usuario" type="MYPACKAGE.persistencia.entidades.Usuario" />
<!-- ... -->
<typeAlias alias="cadena" type="java.lang.String" />
</typeAliases>

Without seeing some of the actual source code, I doubt we can pinpoint any errors, but it might help to take a look at this example on DZone.
One thing they point out in particular is that if you do not follow the correct order in the mybatis-config.xml file, it can cause an exception. It could be that something is just in the wrong place in that file.
If you want to post more of the code, I can try to be of more help.

You package is no available for myBatis. You need to define it using configuration:
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="es.your.packacke"/>
</bean>

Related

Spring Batch - Sporadic issues with Custom FileItemWriter

We have multiple jobs running in Linux environment where jobs run in parallel. We process files with multi-hundred thousands of records in each of these batches. Following is our job steps.xml. This job runs daily but it fails sporadically. It runs 95% of times without any issues but when it fails it fails with below error. Can someone please check what is wrong with our configuration and tell how to address this?
Error:
"org.springframework.batch.item.ItemStreamException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.com.xxx.xx.batchsync.BatchsyncExtractFileItemWriter': Initialization of bean failed; nested exception is java.lang.IllegalStateException: **Not allowed to access field 'outputFile2': java.lang.IllegalAccessException: Class org.springframework.batch.core.jsr.launch.support.BatchPropertyBeanPostProcessor$1 can not access a member of class com.xxx.xx.std.StdFileItemWriter with modifiers "private"**
at org.springframework.batch.jsr.item.CheckpointSupport.open(CheckpointSupport.java:65)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:197)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.jsr.job.flow.support.state.JsrStepState.handle(JsrStepState.java:53)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.jsr.job.flow.JsrFlowJob.doExecute(JsrFlowJob.java:82)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
at org.springframework.batch.core.jsr.launch.JsrJobOperator$2.run(JsrJobOperator.java:675)
at java.lang.Thread.run(Thread.java:809)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.com.xxx.xx.batchsync.BatchsyncExtractFileItemWriter': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Not allowed to access field 'outputFile2': java.lang.IllegalAccessException: Class org.springframework.batch.core.jsr.launch.support.BatchPropertyBeanPostProcessor$1 can not access a member of class com.xxx.xx.std.StdFileItemWriter with modifiers "private"
at org.springframework.beans.factory.support.AbstractAutowireCapa"
Steps.xml:
enter code here
<step id="#{jobParameters['STEPNAME']}-Step1">
<properties>
<property name="JOB_FILE_NAME" value="BatchsyncExtract"/>
<property name="JOBNAME" value="#{jobParameters['JOBNAME']}"/>
<property name="STEPNAME" value="#{jobParameters['STEPNAME']}"/>
<property name="APPL" value="#{jobParameters['APPL']}"/>
<property name="BANK" value="#{jobParameters['BANK']}"/>
<property name="ODATE" value="#{jobParameters['ODATE']}"/>
<property name="PREVENT_JOB_RESTART" value="#{jobParameters['PREVENT_JOB_RESTART']}"/>
<property name="BATCH_ROOT" value="#{jobParameters['BATCH_ROOT']}"/>
<property name="WSBATCH_HOME" value="#{jobParameters['WSBATCH_HOME']}"/>
<property name="BATCH_LOG_FOLDER" value="#{jobParameters['BATCH_ROOT']}/batch/logs"/>
<property name="BUSINESS_MAIN" value="com.xxx.xx.BatchsyncExtractBusinessmain"/>
<property name="PROGRAM_NAME" value="IV-IpBatchsyncExtract"/>
<property name="TODAY" value="#{jobParameters['TODAY']}"/>
....
<property name="PARTITION" value="#{jobParameters['WSBATCH_HOME']}/partinfo/BatchsyncExtract_LdbidIpIdPartition_#{jobParameters['BANK']}.xml"/>
<property name="CHUNKSIZE" value="#{jobParameters['CHUNKSIZE']}" />
</properties>
<listeners>
<listener ref="com.xxx.xx.std.StdStepListener">
</listener>
<listener ref="com.xxx.xx.std.StdChunkListener">
</listener>
</listeners>
<chunk checkpoint-policy="custom" >
<reader ref="com.xxx.xx.BatchsyncExtractInputBDS">
</reader>
<processor ref="com.xxx.xx.std.StdJobStepCursorBased"/>
<writer ref="com.xxx.xx.BatchsyncExtractFileItemWriter">
<properties>
<property name="outputFile1" value="#{jobParameters['BATCH_ROOT']}/batch/import/#{jobParameters['APPL']}/batchsync_extract_#{jobParameters['BANK']}_#{jobParameters['ODATE']}_#{jobParameters['RUN']};default;default" />
<property name="outputFile2" value="#{jobParameters['BATCH_ROOT']}/batch/import/#{jobParameters['APPL']}/batchsync_extract_totals_#{jobParameters['BANK']}_#{jobParameters['ODATE']}_#{jobParameters['RUN']};default;default" />
</properties>
</writer>
<checkpoint-algorithm ref="com.xxx.xx.batch.utils.CustomCheckPointAlgoritmn">
<properties>
<property name="chunkSize" value="#{jobParameters['CHUNKSIZE']}" />
<!--property name="timeInterval" value="#{jobParameters['TIMEINTERVAL']}" /-->
</properties>
</checkpoint-algorithm>
</chunk>
</step>

Dynamic URL for Custom Http-Client - Spring-XD

We have written a custom Http-client for spring XD and planning to use this custom processor for invoking different APIs. However, We have a situation where we need to invoke two different API based on the payload. Apart from using dynamic-router (which writes to a named channel) is there a way we can set the URL dynamically for the http-client to invoke? Here is the current configuration.
<header-filter input-channel="input" output-channel="inputX"
header-names="x-death" />
<service-activator input-channel="inputX" ref="gw" />
<gateway id="gw" default-request-channel="toHttp"
default-reply-timeout="0" error-channel="errors" />
<beans:bean id="inputfields"
class="com.batch.httpclient.HTTPInputProperties">
<beans:property name="nonRetryErrorCodes" value="${nonRetryErrorCodes}" />
</beans:bean>
<beans:bean id="responseInterceptor"
class="com.batch.httpclient.ResponseInterceptor">
<beans:property name="inputProperties" ref="inputfields" />
</beans:bean>
<chain input-channel="errors" output-channel="output">
<transformer ref="responseInterceptor" />
</chain>
<int-http:outbound-gateway id='batch-http'
header-mapper="headerMapper" request-channel='toHttp' url-expression="${url}"
http-method="${httpMethod}" expected-response-type='java.lang.String'
charset='${charset}' reply-timeout='${replyTimeout}' reply-channel='output'>
</int-http:outbound-gateway>
<beans:bean id="headerMapper"
class="org.springframework.integration.http.support.DefaultHttpHeaderMapper"
factory-method="outboundMapper">
<beans:property name="outboundHeaderNames" value="*" />
<beans:property name="userDefinedHeaderPrefix" value="" />
</beans:bean>
<channel id="output" />
<channel id="input" />
<channel id="inputX" />
<channel id="toHttp" />
If it's based on the payload type, something like this should work...
url-expression="payload.getClass().getSimpleName().equals("Bar") ? 'http://foo/bar' : 'http://foo/baz'"
If it's a property on the payload, then
url-expression="payload.foo.equals("bar") ? 'http://foo/bar' : 'http://foo/baz'"
EDIT
or
url-expression="payload.foo.equals("bar") ? '${url1}' : '${url2}'"
This would need changing the property metadata class to rename url and add url2.

getting error in sonar task while executing build.xml

I have configured sonar in my build xml as shown below but upon execution of my build.xml i am getting the error below..can u plas advise how to overcome from this error
target name="sonar">
<echo message="**** thirdparty.lib.dir -- > ${thirdparty.lib.dir}/sonar ****"/>
<sonar:sonar workDir="${build.dir}" key="gtr_61.all.rules:dev" version="1.0" xmlns:sonar="antlib:org.sonar.ant">
<!-- source directories (required) -->
<sources>
<path location="${pps.dir}/src" />
<path location="${pn.dir}/src" />
</sources>
<property key="sonar.host.url" value="https://abc/" />
<property key="sonar.jdbc.url" value="jdbc:oracle:thin:abc" />
<property key="sonar.jdbc.driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property key="sonar.jdbc.username" value="=AAA" />
<property key="sonar.jdbc.password" value="BBB" />
<property name="sonar.scm.url" value="https://svn.ats" />
<property name="sonar.java.source" value="1.5" />
<property name="sonar.language" value="java"/>
<property name="sonar.projectVersion" value="1.0"/>
<tstamp prefix="build-info">
<format property="current-date" pattern="dd-MMM-yyyy" locale="en" />
<format property="current-time" pattern="HH:mm:ss z" locale="en" />
<format property="year-month-day" pattern="yyyy-MM-dd" locale="en" />
</tstamp>
<!-- cobertura -->
<property key="sonar.cobertura.reportPath" value="cobertura-report/coverage.xml" />
<property key="sonar.dynamicAnalysis" value="reuseReports" />
<!-- binaries directories, which contain for example the compiled Java bytecode (optional) -->
<binaries>
<path location="${ps.dir}/build/classes" />
<path location="${omm.dir}/build/classes" />
</binaries>
<!-- path to libraries (optional). These libraries are for example used by the Java Findbugs plugin -->
<libraries>
<path location="${lib.dir}" />
</libraries>
<property key="sonar.profile" value="abc Rule" />
<!--property key="sonar.profile" value="Custom Rules" -->
</sonar:sonar>
the error i am getting is ..
onar
[06:56:15]echo
[06:56:15]**** thirdparty.lib.dir -- > /opt/app//buildAgent-8.0.3/work/pla/lib/thirdparty/sonar ****
[06:56:15]sonar:sonar
[06:56:15]property doesn't support the "name" attribute
If my feeling is correct you're using a very old version of the SonarQube Ant task. Here is the way to configure this SonarQube Ant task: http://docs.codehaus.org/display/SONAR/Analyzing+with+SonarQube+Ant+Task
Here is a latest documentation on the new syntax:
http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Ant+Task

One of '{"http://www.mulesoft.org/schema/mule/jdbc":abstract-query}' is expected

I am trying implement XA Transaction with oracle database connector in Mule Studio. When I try to deploy this mule application on MuleStudio server I am getting below exception.
Exception:
"Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'url' of bean class [oracle.jdbc.xa.client.OracleXADataSource]: Bean property 'url' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?"
Mule Configuration xml file:
<jdbc-ee:oracle-data-source name="Oracle_Data_Source" user="system" password="manager" url="jdbc:oracle:thin:#//localhost:1521/xe" transactionIsolation="UNSPECIFIED" doc:name="Oracle Data Source"/>
<jdbc-ee:connector name="Database" dataSource-ref="oracleJdbcBean" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<jbossts:transaction-manager doc:name="Transaction Manager"/>
<spring:beans>
<spring:bean id="oracleJdbcBean" name="oracleJdbcBean" class="oracle.jdbc.xa.client.OracleXADataSource">
<spring:property name="user" value="system"/>
<spring:property name="password" value="manager"/>
<spring:property name="url" value="jdbc:oracle:thin:#localhost:1521:xe"/>
</spring:bean>
</spring:beans>
<flow name="oraclexatransactionFlow1" doc:name="oraclexatransactionFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="testTable" doc:name="HTTP"/>
<ee:xa-transactional action="ALWAYS_BEGIN" doc:name="Transactional">
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="testQuery" queryTimeout="-1" connector-ref="Database" doc:name="Database">
<xa-transaction action="ALWAYS_JOIN"/>
<jdbc-ee:query key="testQuery" value="select * from test"/>
</jdbc-ee:outbound-endpoint>
</ee:xa-transactional>
</flow>
I have followed the above configuration for other application to make xa transaction work with oracle database but I am getting different exception as below:
Caused by: org.xml.sax.SAXParseException; lineNumber: 195; columnNumber: 55; cvc-complex-type.2.4.a: Invalid content was found starting with element 'xa-transaction'. One of '{"http://www.mulesoft.org/schema/mule/jdbc":abstract-query}' is expected.
Please correct me if I configured anything wrong.
Url property should probably be
<spring:property name="url" value="jdbc:oracle:thin:#//localhost:1521/XE"/>
Uppercase of "URL" worked for me to resolve the first problem i.e.,
<spring:property name="URL" value="jdbc:oracle:thin:#localhost:1521:xe" />
And the second problem was resolved by placing the "xa-transaction" element before the query as below.
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="testQuery" queryTimeout="-1" connector-ref="Database" doc:name="Database">
<xa-transaction action="NONE" />
<jdbc-ee:query key="testQuery" value="select * from test" />

How to pass Mule expression to spring property

I'm looking for a way to assign an exception message to spring property at runtime in mule flow (Mule 3.3.0)
This is how my code-snippet looks like:
<catch-exception-strategy>
<logger message="----->Exception is #[exception.causeException]"
level="INFO" />
<custom-transformer
class="com.company.transformer.VelocityMessageTransformer">
<spring:property name="velocityEngine" ref="velocityEngine" />
<spring:property name="templateName" value="soap11Fault.vm" />
<spring:property name="beanClass">
<spring:bean parent="abstractSoap11ClientFault">
<spring:property name="faultString" value="Invalid Request" />
<spring:property name="detail" value="${exception.causeException}" />
</spring:bean>
</spring:property>
</custom-transformer>
</catch-exception-strategy>
I want to assign exception cause to detail property here:
<spring:property name="detail" value="${exception.causeException}" />
but spring is looking for this property in properties file. I tried doing this also
<spring:property name="detail" value="${#[exception.causeException]}" /> but doesn't work.
Is there a way to pass Mule expression at run-time to Spring property?
Properties are set during the application initialization: the value you want to pass is evaluated at runtime, so that can't work.
What you need to do is make com.company.transformer.VelocityMessageTransformer extend org.mule.transformer.AbstractMessageTransformer. You will then have to override transformMessage(MuleMessage message, String outputEncoding), which will give you access to the current message and its associated exception payload. The exception payload is what you get with the #[exception] expression.

Resources