3
votes

I am working on a spring boot maven project with a custom spring mvc parent project. I am having trouble getting mvn spring-boot:run to work. Here is my POM.xml ignoring the parent tags and groupId,artifactID,etc... tags`

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <netbeans.hint.deploy.server>Tomcat</netbeans.hint.deploy.server>
    <webtarget.root>${basedir}/target/</webtarget.root>
    <webtarget.base>${basedir}/target/tsm-webapp</webtarget.base>
</properties>

<repositories>
    <repository>
        <id>Nexus</id>
        <name>Nexus Managed Internal Repository</name>
        <url>http://nexus.itg.ti.com/nexus/content/groups/public</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20090211</version>
    </dependency>            

    <!-- === web assets === -->

    <!-- jquery -->
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId>
        <version>2.1.3</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery-cookie</artifactId>
        <version>1.4.1-1</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery-validation</artifactId>
        <version>1.14.0-1</version>
    </dependency>

    <!-- font-awesome -->
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>font-awesome</artifactId>
        <version>4.6.3</version>
    </dependency>

    <!-- datatables -->
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>datatables</artifactId>
        <version>1.10.11</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>datatables-plugins</artifactId>
        <version>1.10.11-1</version>
    </dependency>
    <!--<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <type>jar</type>
    </dependency> -->

    <!-- momentjs -->
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>momentjs</artifactId>
        <version>2.11.1</version>
    </dependency>

    <!--ums-->
    <!--new ui changes-->
    <dependency>
        <groupId>com.ti.spring.service</groupId>
        <artifactId>usersvc-ui</artifactId>
        <version>TSM-1.0-27-RELEASE</version>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>tsm-engine</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>servlet-api</artifactId>
        <version>3.0.20100224</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>1.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.4.2</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.0.3.RELEASE</version>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.0.3.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <finalName>tsm-checker</finalName>
    <plugins>

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.0.3.RELEASE</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>


        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
                <attachClasses>true</attachClasses>
                <classesClassifier>classes</classesClassifier>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
            <path>/</path>
            </configuration>
        </plugin>
        <!-- Copies external config files from project to output directory -->
        <!--<plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
            </executions>
        </plugin>-->

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
            </configuration>
        </plugin>

    </plugins>
</build>

` I understand that once I add spring boot dependency to in the Dependency management, the plugins are not auto configured anymore. I was wondering if there was something wrong with my spring boot maven plugin configuration, or if there might be something else causing the problems.

Here is my full stack trace

    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:496)
    at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationContextInitializer : org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer
    at org.springframework.boot.SpringApplication.createSpringFactoriesInstances (SpringApplication.java:448)
    at org.springframework.boot.SpringApplication.getSpringFactoriesInstances (SpringApplication.java:427)
    at org.springframework.boot.SpringApplication.getSpringFactoriesInstances (SpringApplication.java:418)
    at org.springframework.boot.SpringApplication.<init> (SpringApplication.java:266)
    at org.springframework.boot.SpringApplication.<init> (SpringApplication.java:247)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1255)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1243)
    at com.ti.tmg.tsm.checker.Application.main (Application.java:15)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:496)
    at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/KotlinDetector
    at org.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java:169)
    at org.springframework.boot.SpringApplication.createSpringFactoriesInstances (SpringApplication.java:444)
    at org.springframework.boot.SpringApplication.getSpringFactoriesInstances (SpringApplication.java:427)
    at org.springframework.boot.SpringApplication.getSpringFactoriesInstances (SpringApplication.java:418)
    at org.springframework.boot.SpringApplication.<init> (SpringApplication.java:266)
    at org.springframework.boot.SpringApplication.<init> (SpringApplication.java:247)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1255)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1243)
    at com.ti.tmg.tsm.checker.Application.main (Application.java:15)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:496)
    at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.KotlinDetector
    at java.net.URLClassLoader.findClass (URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:357)
    at org.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java:169)
    at org.springframework.boot.SpringApplication.createSpringFactoriesInstances (SpringApplication.java:444)
    at org.springframework.boot.SpringApplication.getSpringFactoriesInstances (SpringApplication.java:427)
    at org.springframework.boot.SpringApplication.getSpringFactoriesInstances (SpringApplication.java:418)
    at org.springframework.boot.SpringApplication.<init> (SpringApplication.java:266)
    at org.springframework.boot.SpringApplication.<init> (SpringApplication.java:247)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1255)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1243)
    at com.ti.tmg.tsm.checker.Application.main (Application.java:15)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:496)
    at java.lang.Thread.run (Thread.java:748)
1

1 Answers

2
votes

Take a look at the results of

mvn dependency:tree

With the parent project included and see if you have more than one version of org.springframework:spring-core

You are loading the correct spring-core version (5.0.7.RELEASE) in this basic pom. But if your parent MVC project is loading a different (older) version of Spring you are probably getting that older version that is missing the class that is referenced in the stack trace (KotlinDetector).