Configuring Spring Batch with Maven - spring

Configuring Spring Batch with Maven. JDK used: 1.6, Spring Batch version 2.1.8.RELEASE; Spring version 3.0.5.RELEASE. Getting run time exception as below:
D:\SpringProject\SpringTry\target>java -jar SpringTry-1.0-SNAPSHOT.jar jobs/helloWorld.xml helloWorldJob
2012-09-02 00:23:51,650 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - <Refreshing org.springframework.context.
support.ClassPathXmlApplicationContext#b29c9d: startup date [Sun Sep 02 00:23:51 IST 2012]; root of context hierarchy>
2012-09-02 00:23:51,769 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path
resource [jobs/helloWorld.xml]>
2012-09-02 00:23:53,854 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path
resource [launch-context.xml]>
2012-09-02 00:23:53,929 ERROR [org.springframework.batch.core.launch.support.CommandLineJobRunner] - <Job Terminated in error: Configuration
problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]
Offending resource: class path resource [jobs/helloWorld.xml]
>
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler fo
r XML schema namespace [http://www.springframework.org/schema/batch]
Offending resource: class path resource [jobs/helloWorld.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
Any suggestion on how to resolve this. Also noticed that Spring 2.5.6 is getting downloaded everytime, along with version mentioned 3.0.5
My manifest looks like:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Build-Jdk: 1.6.0
Main-Class: org.springframework.batch.core.launch.support.CommandLineJobRunner
Class-Path: lib/spring-batch-core-2.1.9.RELEASE.jar lib/xstream-1.3.jar lib/xpp3_min-1.1.4c.jar lib/jettison-1.1.jar lib/spring-aop-2.5.6.jar lib/aopalliance-1.0.jar lib/spring-tx-2.5.6.jar lib/spring-batch-infrastructure-2.1.9.RELEASE.jar lib/spring-beans-3.0.5.RELEASE.jar lib/spring-context-3.0.5.RELEASE.jar lib/spring-expression-3.0.5.RELEASE.jar lib/spring-asm-3.0.5.RELEASE.jar lib/spring-core-3.0.5.RELEASE.jar lib/commons-logging-1.1.1.jar lib/spring-jdbc-3.0.5.RELEASE.jar lib/log4j-1.2.16.jar lib/maven-resources-plugin-2.4.3.jar lib/maven-plugin-api-2.0.6.jar lib/maven-project-2.0.6.jar lib/maven-profile-2.0.6.jar lib/maven-artifact-manager-2.0.6.jar lib/maven-plugin-registry-2.0.6.jar lib/maven-core-2.0.6.jar lib/wagon-file-1.0-beta-2.jar lib/maven-plugin-parameter-documenter-2.0.6.jar lib/wagon-http-lightweight-1.0-beta-2.jar lib/wagon-http-shared-1.0-beta-2.jar lib/jtidy-4aug2000r7-dev.jar lib/xml-apis-1.0.b2.jar lib/maven-reporting-api-2.0.6.jar lib/doxia-sink-api-1.0-alpha-7.jar lib/wagon-provider-api-1.0-beta-2.jar lib/maven-repository-metadata-2.0.6.jar lib/maven-error-diagnostics-2.0.6.jar lib/commons-cli-1.0.jar lib/wagon-ssh-external-1.0-beta-2.jar lib/wagon-ssh-common-1.0-beta-2.jar lib/maven-plugin-descriptor-2.0.6.jar lib/plexus-interactivity-api-1.0-alpha-4.jar lib/wagon-ssh-1.0-beta-2.jar lib/jsch-0.1.27.jar lib/classworlds-1.1.jar lib/maven-artifact-2.0.6.jar lib/maven-settings-2.0.6.jar lib/maven-model-2.0.6.jar lib/maven-monitor-2.0.6.jar lib/plexus-container-default-1.0-alpha-9-stable-1.jar lib/junit-3.8.1.jar lib/plexus-utils-2.0.5.jar lib/maven-filtering-1.0-beta-4.jar lib/plexus-build-api-0.0.4.jar lib/plexus-interpolation-1.13.jar

Most probably you are either:
simply using a version of spring-batch-core jar (Maven dependency) which has version below 2.0. Schema naming works for version 2.0 and above. If it's the case, update your dependency
or
You have the correct (higher than 2.0) version of spring-batch-core in your project's pom.xml, but you also have a transitive dependency which brings into your project an earlier version of spring-batch-core. If that's the case, try the following:
mvn dependency:tree -Dverbose -Dincludes=org.springframework.batch
this will list all the dependencies that bring in their own version of spring-batch dependencies. Add an exclude entry on spring-batch-core for those dependencies, something like this:
<dependency>
<groupId>whatever.group</groupId>
<artifactId>whateverArtifact</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
</exclusion>
</exclusions>
</dependency>

My issue was resolved by adding maven-shade-plugin as detailed in the:
https://stackoverflow.com/a/8574629/1419116

Related

Spring Hadoop - Unable to locate Spring NamespaceHandler for XML schema namespace

I want to enable Hive in my Spring Hadoop project. I understand that we can't use JavaConfiguration so I am using XML. I have an error regarding the Spring Namespace.
Error starting ApplicationContext. To display the auto-configuration
report re-run your application with 'debug' enabled. [2017-10-03
10:26:51.292] - 44342 SEVERE [main] ---
org.springframework.boot.SpringApplication: Application startup failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate Spring NamespaceHandler for
XML schema namespace [http://www.springframework.org/schema/hadoop]
Offending resource: class path resource [hiveContext.xml]
My pom has the following dependency.
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-hadoop-boot</artifactId>
<version>2.5.0.RELEASE</version>
</dependency>
I know some other posts talks about SpringSecurity, but I don't have access to a spring-hadoop-config dependency.

Hibernate (4.3.11-Final) logging not bridging to log4j2?

We are migrating from log4j to log4j2. We use the following libraries and there logging mechanisms:
Tomcat (which uses JULI), Spring 4.2.0 (which uses commons-logging) and Hibernate 4.3.11-Final (which uses jboss-logging).
I have successfully got Spring bridging to log4j2, but Hibernate logging is not working.
According to the Hibernate docs:
To use JBoss Logging with Log4j2, the log4j2 jar would also need to be available on the classpath.
I have the following logging-related jars on my classpath:
commons-logging-1.2.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
log4j-api-2.6.1.jar
log4j-core-2.6.1.jar
log4j-jcl-2.6.1.jar
log4j-slf4j-impl-2.6.1.jar
slf4j-api-1.7.5.jar
slf4j-log4j12-1.7.5.jar
Any ideas why I'm not seeing the results I expect?
The version of jboss-logging included with hibernate-4 is not compatible with log4j2.
I had to import version 3.3.0.Final (should work starting with 3.1.4, according to JBLOGGING-94) for hibernate to work with log4j2.
Here is a shortcut if you use maven :
<dependency> <!-- version working with log4j2 -->
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.0.Final</version>
<scope>runtime</scope>
</dependency>

Spring boot jar Unable to start embedded Tomcat

i have created spring rest services using eclipse IDE. It works fine in eclipse when i run using Debug configurations however when I export it as a executable JAR and run using below command
java -jar cs.jar
it gives me below error:
org.springframework.context.ApplicationContextException: Unable to start embedde
d container; nested exception is org.springframework.boot.context.embedded.Embed
dedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.EmbeddedWebApplicationConte
xt.onRefresh(EmbeddedWebApplicationContext.java:124)
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:474)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationConte
xt.refresh(EmbeddedWebApplicationContext.java:109)
why it's not working as a jar?
You need to check if you have included servlet-api jar in your classpath, if yes, delete it.
If servlet-api is in classpath, it is included in WEB-INF/lib and then the error is thrown because servlet container has already servlet api jar.
Delete servlet-api dependency from maven or gradle if exits or if this dependency is adding by any other module then exclude servlet api dependency like below
<dependency>
<groupId><groupId></groupId>
<artifactId><some dependency></artifactId>
<version><version></version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>

PropertiesLauncher unable to jar files in Uberjar when using Spring Boot

We seem to be having an issue while using propertiesLauncher (layout as ZIP). When we run the jar with or without using -Dloader.path
java -jar myuberjar.jar
We keep getting an error saying that it is not able to find jar file that is present in myuberjar.jar
Caused by: java.lang.IllegalArgumentException: File [/Users/myuser/myuberjar.jar!/lib/jackson-module-jaxb-annotations-2.5.4.jar] referenced by given URL [file:/Users/myuser/myuberjar.jar!/lib/jackson-module-jaxb-annotations-2.5.4.jar] does not exist
at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:73)
at org.hibernate.jpa.boot.archive.internal.JarProtocolArchiveDescriptor.<init>(JarProtocolArchiveDescriptor.java:71)
at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:55)
at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:48)
at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.buildArchiveDescriptor(AbstractScannerImpl.java:95)
at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:70)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.scan(EntityManagerFactoryBuilderImpl.java:725)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:221)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:188)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider$1.<init>(SpringHibernateJpaPersistenceProvider.java:49)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:49)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
Not sure what we are missing.
SpringBoot - 1.2.4.RELEASE
JDK1.8
PropertiesLauncher
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
</configuration>
</plugin>
When i extract the uberjar , i can see all the jars in the lib folder. Bellow are the contents of the manifest file
Manifest-Version: 1.0
Implementation-Title: AppService
Implementation-Version: 0.0.1-SNAPSHOT
Archiver-Version: Plexus Archiver
Built-By: avinash
Start-Class: com.company.app.AppServiceApplication
Implementation-Vendor-Id: com.company.services.app
Spring-Boot-Version: 1.2.4.RELEASE
Created-By: Apache Maven 3.2.1
Build-Jdk: 1.8.0_25
Implementation-Vendor: Pivotal Software, Inc.
Main-Class: org.springframework.boot.loader.PropertiesLauncher
The issue is not with Spring Boot properties launcher, but more with Hibernate jars as described in the bug below.
https://hibernate.atlassian.net/browse/HHH-4161

ClassCastException: Can't cast oracle.sql.ARRAY to oracle.sql.ARRAY in JBoss 7.1.1.Final

DemoApp is spring integration project deployed in jboss 7.1.1.Final
The result returned from a stored procedure contains object of oracle.sql.ARRAY (object referring ojdbc jar of jboss module)
And I tried converting to oracle.sql.ARRAY which throwing exception
Code:
URL resultJarLocation= resultMap.get("returnObj").getClass().getProtectionDomain().getCodeSource().getLocation();
URL appJarLocation = oracle.sql.ARRAY.class.getProtectionDomain().getCodeSource().getLocation();
System.out.println("resultJarLocation : " + resultJarLocation);
System.out.println("appJarLocation : " + appJarLocation);
oracle.sql.ARRAY returnObj=(oracle.sql.ARRAY)resultMap.get("returnObj");
EXCEPTION:
org.springframework.messaging.MessageHandlingException: java.lang.ClassCastException: oracle.sql.ARRAY cannot be cast to oracle.sql.ARRAY
The application ARRAY class is referring ojdbc jar in the deployed application.
where as result set ARRAY class referreing ojdbc jar jboss module
Sys Output:
resultJarLocation : jar:file:/<JBOSS_HOME>/modules/com/oracle/ojdbc6/main/ojdbc6.jar
appJarLocation : vfs:/<JBOSS_HOME>/bin/content/DemoApp.war/WEB-INF/lib/ojdbc6.jar
You are trying to cast between classes loaded by different classloaders. JVM distinguishes classes not only by name and package but also by the classloader used. In other words, from JVM perspective is like trying to cast from say String to Long; you cannot.
The only think you can do is configuration. Set up either for the same classloader to be used, or the classloaders to be in the same hierarchy, to take advantage of delegation.
I am not very familiar with JBoss (especially current versions) but I know it has (or used to have in the past) some very different classloading strategy than other application servers. Checking with its documentation on classloading would be my first option.
I solved the problem by changing the ojdbc jar's scope as 'provided' as this will not include the jar in the WEB-INF/lib.
And then added the Dependencic of jboss 7 module 'com.oracle.ojdbc6' in pom.. which will add the Dependencies attribute in META-INF/MANIFEST.MF file, as a result on deployment the jboss 7's ojdbc jar will be uses for object creation for both jboss and application, and the classloader will be the jboss's classloader.
Bellow are the code in pom.
1) Manifest entry :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Dependencies>com.oracle.ojdbc6</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
2) Dependency as Provided:
<dependency>
<scope>provided</scope>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.2.0</version>
</dependency>
META-INF/Manifest.MF file will be generated with dependency entry
Manifest-Version: 1.0
Dependencies: com.oracle.ojdbc6
Built-By: Mrinmoy
Build-Jdk: 1.7.0_65
Created-By: Apache Maven 3.2.2
Archiver-Version: Plexus Archiver

Resources