gpt4 book ai didi

java - Spring-Boot-Maven-Plugin,无法实例化接口(interface) org.springframework.context.ApplicationContextInitializer

转载 作者:行者123 更新时间:2023-11-30 10:14:23 30 4
gpt4 key购买 nike

我正在开发一个带有自定义 spring mvc 父项目的 spring boot maven 项目。我无法使 mvn spring-boot:run 正常工作。这是我的 POM.xml,忽略了父标签和 groupId、artifactID 等...标签`

<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>

`我知道一旦我在依赖管理中添加了 spring boot 依赖,插件就不再自动配置了。我想知道我的 spring boot maven 插件配置是否有问题,或者是否有其他原因导致了问题。

这是我的完整堆栈跟踪

    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)

最佳答案

看看结果

mvn dependency:tree

包含父项目,看看是否有多个版本的org.springframework:spring-core

您正在这个基本 pom 中加载正确的 spring-core 版本 (5.0.7.RELEASE)。但是,如果您的父 MVC 项目正在加载不同(较旧)版本的 Spring,您可能会得到缺少堆栈跟踪 (KotlinDetector) 中引用的类的较旧版本。

关于java - Spring-Boot-Maven-Plugin,无法实例化接口(interface) org.springframework.context.ApplicationContextInitializer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50912944/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com