Error while deploying Spring Batch Application - java.lang.NoClassDefFoundError: org/codehaus/jettison/mapped/MappedXMLOutputFactory - spring

I am stuck with this error from last few days , while loading the spring batch application,it keep on giving error
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in ServletContext resource [/WEB-INF/classes/spring/batch/jobs/config/context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jettison/mapped/MappedXMLOutputFactory
I have added jettison to my pom and here below my pom file looks like
org.codehaus.jettison
jettison
1.3.2
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-oxm
${spring.version}
org.springframework.batch
spring-batch-test
${spring.batch.version}
jettison
org.codehaus.jettison

pom.xml should have dependency like :
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.3.2</version>
</dependency>
Also, do you see jettision-1.3.2.jar in your maven dependecies?
if you are using eclipse, ctr+sft+t : are you able to see this class?

Related

Runtime Error in SprinBoot project : unable to find SqlSessionFactory

I have a simple SpringBoot project in IntelliJ that I generated at http://start.spring.io. I added a dependency from the local repository and it was successfully imported. This library depends on the different local library.
I am able to Build my project successfully, however when I am trying to Run it I am getting runtime error. I added new dependency to my project that contains the class which was not found during the startup but it didn't resolve my issue and I am still having problems on the startup.
Here is the original dependency I added to my project :
<dependency>
<groupId>connect_mgr</groupId>
<artifactId>connect-mgr</artifactId>
<version>1</version>
Inside this "connect_mgr" project there is a dependency on the different library :
<dependency>
<groupId>services_core</groupId>
<artifactId>services-core</artifactId>
<version>1</version>
</dependency>
There is also an implementation in the "services_core" project :
#Bean
#DependsOn("sqlSessionFactory")
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
In my Project I also added a dependency to IBatis-Core that contains "SqlSessionFactory" class.
And still, on the startup of my project I am getting this error :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/config/MyBatisMapperConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.io.FileNotFoundException: class path resource [null] cannot be opened because it does not exist
Main class in my projec resides in "services_core" project.

Are spring-boot-starter-data-jpa and Liquibase incompatible?

I tried to setup a new Spring Boot 2.4.3 project and I want to include Liquibase as well as Spring Data JPA.
To achieve this I use the following dependencies in my POM:
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
</dependency>
or...
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>${liquibase.version}</version>
</dependency>
...respectively and
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
with
<kotlin.version>1.4.31</kotlin.version>
<liquibase.version>4.3.1</liquibase.version>
<hibernate.version>5.4.29.Final</hibernate.version>
Yet, in the beginning, I don't have any DB setup so far and in application.yaml you can find:
server:
port: 8080
spring:
liquibase:
change-log: classpath:db/changelog/db.changelog.yml
wherbey db.changelog.yml is empty.
A Maven install using the spring-boot-starter-data-jpa dependency results in:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is
liquibase.exception.ChangeLogParseException: Empty file classpath:db/changelog/db.changelog.yml
Caused by: liquibase.exception.ChangeLogParseException: Empty file classpath:db/changelog/db.changelog.yml
while when commenting out this dependency the build succeeds.
I found out that the empty db.changelog.yml file must contain at least:
databaseChangeLog:
- changeset:
although on https://docs.liquibase.com/concepts/basic/changelog.html an example is given that an empty changelog.yaml file needs to look like:
databaseChangeLog:
, but this results in a BeanCreationException:
Caused by: liquibase.exception.ChangeLogParseException: Could not find databaseChangeLog node

Spring Boot application breaks after upgrade to Apache Derby 10.15 -- why?

During a round of SOUP upgrades in a Spring Boot application, I bumped Apache Derby from 10.14.1.0 to 10.15.1.3. Now the tests fail with this beauty (snipped, full stacktrace here):
Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration':
Unsatisfied dependency expressed through constructor parameter 0
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSource':
Invocation of init method failed
Caused by: java.lang.IllegalStateException:
Failed to replace DataSource with an embedded database for tests.
If you want an embedded database please put a supported one on the
classpath or tune the replace attribute of #AutoConfigureTestDatabase.
What is going here? Do I need to change any configuration?
Apache Derby requires Java 9 from 10.15.x on which Spring Boot does currently not support.
See also spring-boot#16433.
I just want to answer with what it took me to get Derby 15.2.0 to work with Spring Boot 2.4.4 with derby in embedded mode, on top of Java 11. Spring Boot 2.4.4 works out of the box with Derby 14, although you will get some warning as spring boot starts. Upgrading apache derby to 15.2.0 fixed that for me.
In pom, both derby and derbytools dependencies defined:
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.15.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbytools</artifactId>
<version>10.15.2.0</version>
</dependency>
Then in your apps properties file:
spring.datasource.driver-class-name=org.apache.derby.iapi.jdbc.AutoloadedDriver
Instead of:
spring.datasource.driver-class-name=org.apache.derby.jdbc.EmbeddedDriver
After that, I now get a good startup of Spring Boot with no warnings or anything that raises concerns.

Getting "Error creating bean with name 'springSecurityFilterChain'" in Spring Boot

I got this error when I run the application. I tried to solve this problem by reading several posts but it makes no sense.
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
and
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.RuntimeException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
In the exception stack trace it seems not able to find the JAXB-API . Do you have this dependency to your project - jaxb-api.
Java 11 removed the Java EE modules: java.xml.bind (JAXB) - REMOVED
You can fix the issue by using alternate versions of the Java EE technologies. Simply add Maven dependencies that contain the classes you need:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.2</version>
</dependency>
For Details Read This StackOverflow Answer

Maven: add external JAR to spring boot project while building jar

One external is added as dependency in spring boot project with scope=system. Build is successful and when running the project from eclipse it is successful. But when I am running the project from command project using command java -jar springBoot.jar. then it is failed with below exception :
Unsatisfied dependency expressed through field 'jdbcTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource
Add below tag in pom.xml. When adding below tag then it will include jars having scope = system.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>

Resources