Spring Boot Application无法解析为某种类型,但我在pom.xm中导入它

时间:2016-10-08 17:47:26

标签: maven spring-boot pom.xml

我在pom.xml中添加了spring boot但是它仍然给出了错误。 任何人都可以帮助我。

给出错误导入org.springframework.boot.autoconfigure.SpringBootApplication无法解析

和 SpringBootApplication无法解析为某种类型 My Main method is

我的pom。 xml是

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

1 个答案:

答案 0 :(得分:-2)

你的pom看起来几乎是正确的,但很少有注意事项

  1. 无需添加依赖项'javax.servlet-api',可从'spring-boot-starter-web'中获取
  2. 你可能错过了'spring-boot-maven-plugin',它不是强制性的,但你可能想要在你的项目中。它为您提供了一些简单的maven目标。
  3. tokens = ['that','produces','cash','flow','from','operations','with','cash']
    keywords = ['cash','flow']
    
    keywords_in_tokens = [x for x in keywords if x in tokens]
    count_keywords_in_tokens = len(keywords_in_tokens)
    
    print(keywords_in_tokens)
    print(count_keywords_in_tokens)
    

    如果您正在运行eclipse,您可以像往常一样生成.classpath文件 mvn eclipse:eclipse ,一旦完成你的ide应该看起来很好

    然后 mvn spring-boot:run 应该设置你的应用程序运行