I am new to Spring Boot. I have gone through the documents and few tutorials. What I understood from them, Spring Boot makes development easy. Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
Till tutorials it was fine.
But suppose you already have an application (SpringMVC+Hibernate+MySql) can I take advantage of Spring Boot in this application? To figure out answer I decided to integrate Spring Boot in one project. I downloaded a sample working code from http://www.journaldev.com/3531/spring-mvc-hibernate-mysql-integration-crud-example-tutorial and tried to integrate Spring Boot. I am not able to get this working. I am getting below exception.
Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener : org.springframework.boot.logging.ClasspathLoggingApplicationListener
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:414)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:394)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:385)
at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:263)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
at com.journaldev.spring.Application.main(Application.java:14)
Caused by: java.lang.NoClassDefFoundError:
org/springframework/context/event/GenericApplicationListener
Now I am completely confused. I am getting impression that Spring Boot cannot be integrated above kind of application. You need to devlop application from scratch. Not sure whether I am correct or not. Please explain me how can I take advantages of Spring Boot in already developed Spring application?
Below is the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.journaldev.spring</groupId>
<artifactId>SpringMVCHibernate</artifactId>
<name>SpringMVCHibernate</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>4.0.3.RELEASE</org.springframework-version>
<org.aspectj-version>1.7.4</org.aspectj-version>
<org.slf4j-version>1.7.5</org.slf4j-version>
<hibernate.version>4.3.5.Final</hibernate.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Apache Commons DBCP -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- Spring ORM -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- #Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
</project>
Caused by: java.lang.NoClassDefFoundError:
org/springframework/context/event/GenericApplicationListener
From the above error, application is unable to find the class defined from the jar dependencies. GenericApplicationListener is added from spring version 4.2 AFAIK.
<org.springframework-version>4.0.3.RELEASE</org.springframework-version>
Upgrade your spring version to >4.2 and recheck.
Here comes the way to dependency management. Spring-boot makes it easy to go. Here is what spring boot documentation says.
Provide opinionated 'starter' POMs to simplify your Maven
configuration
Automatically configure Spring whenever possible
We don't have to worry about the dependencies much apart from the Database vendor specific jars to be added as per requirement.
API
I am getting impression that Spring Boot cannot be integrated above kind of application. You need to devlop application from scratch.
No, When we have the maven configuration with us, it is all about changing the root pom with their dependencies. Its all about dependency abstraction. Building application from root level is undoubtedly easy but by following the principles of maven, we can even make the existing application to follow spring-boot.
Please explain me how can I take advantages of Spring Boot in already developed Spring application?
Study about these dependencies, Analyse their root POM. They give us all the dependencies that you add in normal application. In a way helps us with build configurations and many more boiler plate dependencies.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Apart from the above,
What is parenting in maven
How to change version in child pom
Will help you in customizing the applications.
Just want to add, I finished all my R&D and solve all the problems. I created an Spring Boot application and published it over github.
https://github.com/gauravdubey58/SpringBootLegacy
In this application I am using Spring MVC and Hibernate with xml configuration.
Spring Boot manages dependencies for you. All dependencies in a release for springboot are tested to work together with sensible defaults. It is possible to define you own or override, but its recommended that you do not. Refer to official documentation below :
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-dependency-management
Each release of Spring Boot is associated with a base version of the
Spring Framework so we highly recommend you to not specify its version
on your own.
For existing application it may be hard to get versions match, it surely is doable all that will depend on application complexity, time on your hand and regression testing. From migration path standpoint comment all dependencies managed by you and let springboot pull that into application e.g. spring-boot-starter-web is already pulling a spring mvc 4.2.4 while your pom define it as 4.0.3.RELEASE. This applies to other dependencis. Hibernate and spring orm will be pulled by spring-boot-starter-data-jpa.
I have fully functional enterprise application with almost same dependencies by using spring-boot-starter-web, spring-boot-starter-data-jpa, spring-boot-starter security and spring-boot-starter-freemarker and jar for DB client. But our application was fairly new when we migrated.
Related
I have a problem building the spring boot application. We need to build the project with the 'lib/bin/conf' structure using the maven. I did it with another project and there is no problem. But now, a conflict occurred and an action is recommended.
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.<init>(DefaultSingletonBeanRegistry.java:88)
The following method did not exist:
'java.util.Map org.springframework.core.CollectionFactory.createConcurrentMapIfPossible(int)'
The calling method's class, org.springframework.beans.factory.support.DefaultSingletonBeanRegistry, is available from the following locations:
jar:file:/Users/user/.m2/repository/org/springframework/spring/2.5.5/spring-2.5.5.jar!/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.class
jar:file:/Users/user/.m2/repository/org/springframework/spring-beans/5.3.18/spring-beans-5.3.18.jar!/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.class
The calling method's class was loaded from the following location:
file:/Users/user/.m2/repository/org/springframework/spring/2.5.5/spring-2.5.5.jar
The called method's class, org.springframework.core.CollectionFactory, is available from the following locations:
jar:file:/Users/user/.m2/repository/org/springframework/spring-core/5.3.18/spring-core-5.3.18.jar!/org/springframework/core/CollectionFactory.class
jar:file:/Users/user/.m2/repository/org/springframework/spring/2.5.5/spring-2.5.5.jar!/org/springframework/core/CollectionFactory.class
The called method's class hierarchy was loaded from the following locations:
org.springframework.core.CollectionFactory: file:/Users/user/.m2/repository/org/springframework/spring-core/5.3.18/spring-core-5.3.18.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.beans.factory.support.DefaultSingletonBeanRegistry and org.springframework.core.CollectionFactory
How can I solve this problem? Some of the libraries provided by the company have been deleted. This is my pom file.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>...</name>
<properties>
<java.version>11</java.version>
<finalName>${project.artifactId}-${project.version}</finalName>
<logback.version>1.2.9</logback.version>
<log4j.version>2.17.0</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
<version>4.34.0</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-jdbc-template</artifactId>
<version>4.34.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- vault -->
<dependency>
<groupId>org.springframework.vault</groupId>
<artifactId>spring-vault-core</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<!-- log4j -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<!-- Swagger 2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- Apache Commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>5.2.2.RELEASE</version>
</dependency>
<!--proxy-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.13</version>
</dependency>
</dependencies>
<build>
<finalName>${finalName}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Spring 2.5.5 has been obsolete for 12 years; there's no reason for you to have it. Furthermore, it makes absolutely no sense whatsoever to have a lib directory with Maven; dependency management is much of what Maven is for.
I see nothing in your POM that would pull in Spring 2.5.5. Is it possible that something else related to your project made a typo and intended to include Spring Boot 2.5.5? In any case, determine where this is coming from (mvn dependency:tree) and fix that.
DefaultSingletonBeanRegistry and CollectionFactory are duplicate in spring-2.5.5, actually they are already included in spring-beans and spring-core.
Execute 'mvn dependency:tree -Dverbose' to see how spring-2.5.5 is included, exclude it and try again
I have NOT worked on Java, SpringBoot and Maven a lot. I had gone through several posts for the issue mentioned above, but nothing was close to my scenario
I compile and package SpringBoot project using Maven with JDK1.8.0_172 on Windows 10
I then deploy this packaged war to Linux server (RHEL with JDK1.8.0_201 and Tomcat 8)
When I hit the URL http://localhost:8080/MyApp, tomcat errors and I don't see anything wrong in Tomcat logs
I am not sure what I am doing wrong. Any help is highly appreciated
Error from Tomcat Server
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
POM.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.htc.myapp.main</groupId>
<artifactId>SpringProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.bmc.remedy</groupId>
<artifactId>remedyapi</artifactId>
<version>8.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/remedyapi-8.1.jar</systemPath>
</dependency>
<!-- JSTL tag lib -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<!-- <dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency> -->
<!-- Tomcat for JSP rendering -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<!-- <dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency> -->
<!--
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency> -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.3</version>
</dependency> -->
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-client -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
</dependencies>
<build>
<finalName>MyApp</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
<procedure><packaging>war</packaging></properties>
</project>
EDIT
I installed Tomcat 7 and was able to open the application. However, invoking some action on application throws 'Something went wrong'
Looking into Tomcat logs it appears there's some issue with DB connectivity
Error on Logs
2019-06-19 12:42:55.943 ERROR 20177 --- [bio-8080-exec-3] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: No suitable driver found for jdbc:jtds:sqlserver://10.xxx.xxx.xxx:1433/MyDatabase;user=username;password=pwd
I copied jtds-1.3.1.jar to $TOMCAT_instance/lib directory and also tried used the following DB settings but NOTHING worked
db_LMS.url=jdbc:jtds:sqlserver://10.xxx.xxx.xxx:1433;databaseName=MyDatabase;integratedSecurity=true;user=username;password=pwd
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
db_LMS.url=jdbc:jtds:sqlserver://10.xxx.xxx.xxx:1433/MyDatabase;user=username;password=pwd
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
Any help on this issue is highly appreciated
Added the following in $TOMCAT_HOME/conf/server.xml resolved the Issue
By default Tomcat disable loading Java driver file to prevent memory leak issue
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" driverManagerProtection="false" />
This error simply means that there is no "code that handles" the request associated with the URL you type. Usually, tomcat doesn't log these attempts, because they won't really add any helpful information someone tried to access the resource that doesn't exist, so what?
Check the context path under which the application gets deployed, maybe it's not MyApp but something else?
Also check that your request is really valid (You issue the right HTTP method, send correct headers and so forth).
Last but not least, make sure that your controllers are indeed recognized by spring during the startup (you should see something like url is mapped to some info about the controller) in the startup log of spring application.
Another possible reason is that the resource is protected and cannot be accessed without some sort of identification, like credentials. In this case check the security configurations as well (since its a very broad topic by its own, I don't think I can be more specific in the context of this question).
I am trying to integrate apache spark with spring-boot cassandra project. But while running the project it gives following error:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: org/spark_project/guava/collect/MapMaker] with root cause
java.lang.ClassNotFoundException: org.spark_project.guava.collect.MapMaker
I checked my maven dependencies and the mapmaker file was present there in the spark-network-common_2.11.jar within 'org/spark_project/guava/collect/'.
Here is the pom file dependencies I am using:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.datastax.cassandra/cassandra-driver-core -->
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-network-common -->
<!-- <dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-network-common_2.10</artifactId>
<version>1.3.0</version>
</dependency> -->
<!-- <dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-network-common_2.11</artifactId>
<version>2.2.1</version>
</dependency> -->
<!-- https://mvnrepository.com/artifact/com.datastax.cassandra/cassandra-driver-mapping -->
<!-- <dependency> <groupId>com.datastax.cassandra</groupId> <artifactId>cassandra-driver-mapping</artifactId>
<version>3.5.0</version> </dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.datastax.spark/spark-cassandra-connector -->
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector_2.11</artifactId>
<version>2.0.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
The spark-network-common_2.11.jar comes along with the spark-core dependency, still I tried to add it separately, but even that didn't work.
What could be the problem that spring-boot can't identify the mapmaker file at runtime?
Any help is appreciated.
The package path of "org.spark_project.guava.collect.MapMaker" Heavily implies that the guava package has been relocated into the spark_project in order to avoid dependency hell.
Things like this are controlled by the build process, and can be easily overlooked sources of incompatibility between libraries.
My instinct is that you may be using mis-matching versions of libraries, that whilst technically may be compatible, arn't because of guava being relocated differently.
You have
<artifactId>spark-network-common_2.10</artifactId>
Commented out, when the other dependencies have 2.11 listed.
These represent the version numbers of the Scala Language+runtime used and should match across any projects that use Scala.
Which class / library is attempting to load the relocated Guava? This should give you a large hint towards which library is potentially outdated/mismatched.
I wrote this pom.xml based on an spring boot sample.
And when I started my app, I got this error:
SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.
I'm totally new to Java and Maven, and stuck here for quite a while.
I tried to wrote some exclusions in dependency. But it didn't work out. I have no idea which package should be excluded from which. If so, how can the package which is depended on, work normally?
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-samples</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-web-secure-jdbc</artifactId>
<name>Spring Boot Web Secure JDBC Sample</name>
<description>Spring Boot Web Secure JDBC Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<!-- Compile -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>3.0.0-alpha2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
This happens because spring-boot-starter is pulling in the log4j-over-slf4j dependency, and one of your other dependencies is pulling in log4j.
run mvn dependency:tree and you should be able to find which dependency is pulling in the unwanted log4j and exclude it with
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
It may only be one of those depending on what you see on thee mvn dependency:tree
If you would rather use log4j then obviously just exclude log4j-over-slf4j from spring-boot-starter instead.
This problem is due to the endless loop between logging facade and logging framework call.
https://www.slf4j.org/codes.html#log4jDelegationLoop
My scenario is slightly more complicate. Besides this loop problem. I have two logging framework.
I end up excluding log4j-over-slf4j and logback-classic.
I saw on your pom.xml there's no dependency for log4j. You should put this to your pom.xml:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
I am trying to learn Hibernate-Spring-Struts using the example Struts 2 + Spring + Hibernate integration example.
But after creating the pom.xml getting this error :
Missing artifact javax.transaction:jta:jar:1.0.1B
I made a progress only up to creating the pom.xml file and made the changes to include most recent libraries.
Here is my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>S3HMaven</groupId>
<artifactId>S3HMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>S3HMaven</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.0.1B</version>
</dependency>
<!-- Struts 2 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.1.8</version>
</dependency>
<!-- Struts 2 + Spring plugins -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.15.2</version>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
<!-- Spring framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>2.5.6</version>
</dependency>
<!-- Hibernate core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.7.ga</version>
</dependency>
<!-- Hibernate core library dependency start -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<!-- Hibernate core library dependency end -->
<!-- Hibernate query library dependency start -->
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<!-- Hibernate query library dependency end -->
</dependencies>
</project>
I tried with and without dependency for javax.transation. Did not make difference. Can any one tell me what am I doing wrong ? What should I do to get rid of it?
In my case i tried example from mkyong
jsf-2.0 spring hibernate integration example
When i got the exception i searched alot i was using spring sts suit tool , and eclipse MARS with JDK 8 the solution was
I changed pom to 1.1 instead of 1.0.1B
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
And if it could not be downloaded automatically from m2 repo you should download it manualy (you can check this in the repo in folder C:\Users\pc1\.m2\repository\javax\transaction\jta\1.1\jta-1.1.jar )
and check the maven dependency in project properties it should not give you an error in the lib tab.
References :
reference 1
reference 2
reference 3
reference 4
reference 5
Related issues might appear after you solve this if you are applying the tutorial:
1-http://www.mkyong.com/web-development/the-web-xml-deployment-descriptor-examples/
2-http://jonathan.lalou.free.fr/?p=2026
3-Error creating bean with name 'sessionFactory' Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
Tomcat error: Not Found in ExternalContext as a Resource
The error in your pom.xml because you mess up different versions of Struts core and plugins.
Change
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.15.2</version>
</dependency>
I don't know why do you need JTA 1.0.1B but you could change hibernate to 3.3.2 (at least, without headaches)
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.3.2.ga</version>
</dependency>
it has a recommended dependency for JTA 1.1.
Create a new project from pom.xml then add source files to it.
Which repository are you using?
Add the java.net Maven repository as below.
<repository>
<id>java.net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
This repo worked for me:
<repository>
<id>webpublico-repository</id>
<name>Webpublico Nexus Repository</name>
<url>http://repository.webpublico.com.br/repository/maven-public/</url>
</repository>
some approach from Unable to resolve javax.transaction dependency
clear the .ivy/cache folder. it works, but takes very long time.
At the moment, it may be unnecessary. But I think we should update this ticket for someone.
It works for me. Change porm.xml
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.16</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.3.Final</version>
</dependency>