问题描述
我在pom.xml中添加了spring boot,但仍然给出错误.谁能帮我.
I have added the spring boot in pom.xml but still it is giving an error.Can anyone help me.
出现错误导入org.springframework.boot.autoconfigure.SpringBootApplication无法解析
It is giving error The import org.springframework.boot.autoconfigure.SpringBootApplication cannot be resolved
和SpringBootApplication无法解析为一种类型
and SpringBootApplication cannot be resolved to a type
我的pom. xml是
My pom. xml is
<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.webapp</groupId>
<artifactId>proj1</artifactId>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
<version>0.0.1-SNAPSHOT</version>
<name>proj1 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<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>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>proj1</finalName>
</build>
</project>
推荐答案
您的pom看起来几乎是正确的,但是没有什么要注意的
Your pom looks almost correct, but few things to note
- 无需添加依赖项"javax.servlet-api",可从"spring-boot-starter-web"获得它
- 您可能会丢失"spring-boot-maven-plugin",它不是强制性的,但您可能希望在项目中使用它.它为您提供了一些简单的Maven目标供您运行.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
如果您正在运行日食,则可以像平常一样生成.classpath文件 mvn eclipse:eclipse ,一旦完成,您的助手就应该看起来不错
if your running eclipse you can generate your .classpath files just as usual mvn eclipse:eclipse, once done your ide should look fine
然后 mvn spring-boot:run 应将您的应用设置为运行
then mvn spring-boot:run should set your application running
这篇关于Spring Boot Application无法解析为类型,但我将其导入pom.xm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!