-1

I am migrating existing Spring project into Spring boot.unable to run spring boot application its showing following error.

enter image description here

The error log says there is a conflict on tomcat-embed-core. In eclipse Dependency hierarchy of porm.xml is given below enter image description here

i exclude the maven architect ,and try to run the application its showing following error

enter image description here

porm.xml

    <modelVersion>4.0.0</modelVersion>
    <artifactId>MyService</artifactId>
    <packaging>jar</packaging>
    <properties>
        <java.version>1.8</java.version>
        <!-- 2.1.3.RELEASE -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <springframework.boot.version>2.1.7.RELEASE</springframework.boot.version>
    </properties>

    <name>MyService</name>
    <url>http://maven.apache.org</url>
    <dependencies>  
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sybase.jdbc3.jdbc</groupId>
            <artifactId>jconn3</artifactId>
            <version>${jconn3.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>               
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-juli</artifactId>
            <version>${tomcat.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jdbc</artifactId>
            <version>${tomcat.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>

                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>

            </plugins>
        </pluginManagement>
    </build>
</project>

what was wrong in this porm.xml

arj
  • 887
  • 1
  • 15
  • 37
  • Could you also post your complete pom.xml or at least more, I don't see the spring-boot-import do you use the parent pom or the other way? – Martin van Wingerden Sep 19 '19 at 05:56
  • I think you do not need to import `tomcat-jdbc`, just import `spring-boot-starter-web`, `spring-boot-starter-data-jpa``spring-boot-starter-test` is sufficient, Ref: https://github.com/dineshbhagat/spring-boot-web-jpa/blob/master/build.gradle – dkb Sep 19 '19 at 05:58
  • am using spring-boot-maven-plugin – arj Sep 19 '19 at 05:59
  • any specific reason to add `tomcat-juli` ? – dkb Sep 19 '19 at 05:59
  • or create dummy project from https://start.spring.io/, add all dependencies and compare the pom.xml with your project's pom.xml – dkb Sep 19 '19 at 06:01

2 Answers2

1

Where is

${tomcat.version}

defined?

That version probably does not match the tomcat version that auto magically is included with spring boot items.

And thus the conflict.

Go here:

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web/2.1.7.RELEASE

And start following the COMPILE dependencies, and you'll find the versions that are auto included with 2.1.7.RELEASE. and you have to alter the other includes that are overwriting the springboot auto include tomcat versions.

Again, follow the COMPILED dependency trail.


So below is what you should find by crawling the COMPILED dependency trail (from immediately above in my answer)

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat/2.1.7.RELEASE

And you'll find you need to set

tomcat.version to

9.0.22

By defining tomcat.version as 8.x, you are breaking it.


Another way to put it

You have to go ~way~ back to springboot 1.5.2.RELEASE or 1.5.3.RELEASE

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat/1.5.2.RELEASE

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat/1.5.3.RELEASE

(Again, in the two above links, looked at the COMPILE dependencies)

To find a version of tomcat (that is auto included with springboot) that gets close to tomcat 8.5.x (where 8.5.x is the one you are attempting to use)

That's pretty old.


The principal you are missing is that springboot auto includes dependencies. And anything else you import has to play nice with everything springboot auto includes.

And your current value for tomcat.version is NOT playing nice with everything springboot 2.1.7.RELEASE is auto including.


And now that you've been through all of that. You'll find you'll make your life easier if you engage the springboot world more completely.

Alot of times, springboot will have a (sub)package that will bring in the thing you really desire.

spring-boot-starter-jdbc

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc/2.1.7.RELEASE

You would probably be better off bringing that package in, vs hand-picking ones. Aka, get rid of your "tomcat-jdbc" include and see if the spring-boot-starter-jdbc can give you what you want.

The curse/blessing of spring-boot is that it is its own universe. But if you engage, you probably want to play by its rules more often than not.


PS

It is pom.xml, not porm.xml

granadaCoder
  • 26,328
  • 10
  • 113
  • 146
0

Try adding spring-boot-starter-tomcat as a dependency:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

Remove tomcat-juli and tomcat-jdbc dependencies. If you need JDBC support, add the corresponding starter:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

If you use JSP views, you will probably need the following dependencies as well:

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>

Also, pay attention to your dependencies versions. Spring Boot's parent POM defines version management for many common artifacts so you don't need to set the <version></version> for these libraries. See https://docs.spring.io/spring-boot/docs/2.1.7.RELEASE/reference/htmlsingle/#appendix-dependency-versions

aaguilera
  • 1,080
  • 10
  • 27