Ore*_*ton 28 java spring spring-mvc maven
我已经使用Spring Initializer设置了一个spring boot项目,我尝试了几次来创建一个新项目或者使用依赖项,一切似乎都已到位.
我正在使用STS(Spring Tool Suite),它显示有关从org.springframework.boot包中导入的错误.运行应用程序会引发异常:
线程"main"中的异常java.lang.Error:未解决的编译问题:SpringApplication无法解析.
com.example.DemoApplication:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<start-class>com.example.DemoApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
我正在使用带有STS的Java 1.8.
小智 24
更改spring boot parent的版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
Run Code Online (Sandbox Code Playgroud)
小智 6
如果以下步骤不起作用:
将我的Spring Boot 1.4.2.RELEASE替换为1.5.10.RELEASE
出现此错误的原因可能是同一版本的多个版本已下载到您的maven本地存储库文件夹中。
因此,请按照以下步骤清除所有现有的存储库jar,并根据POM.xml中定义的依赖关系从头开始下载所有资源。
试试这个,它可能也适合你。
这对我在 v2.1 和 v2.4 上都有效
小智 1
当您将应用程序作为 jar 运行时,您的Manifest.MF文件应该知道哪个类具有 main 方法。
要在 SpringBoot 编译代码时添加此信息,请start-class在 pom 文件中添加属性。
例如:
<properties>
<start-class>com.example.DemoApplication</start-class>
</properties>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
98036 次 |
| 最近记录: |