简体   繁体   English

添加 SourceRoot 会导致 Spring Boot 应用程序出错

[英]Adding SourceRoot causes errors in spring boot application

I created a spring boot application in intelliJ using spring initializr, after I created the project there was no run configuration found.我使用spring initializr在intelliJ中创建了一个spring boot应用程序,在我创建项目后没有找到运行配置。 also the DemoApplication.java file was not labeled a class in the project overview nor was it selectable when trying to use it as the main class.此外,DemoApplication.java 文件在项目概述中没有标记为类,也没有在尝试将其用作主类时可选。 I found a stack overflow question( Spring Boot Program cannot find main class ) that said to add the class path.我发现了一个堆栈溢出问题( Spring Boot 程序找不到主类),它说要添加类路径。 when I tried it only two options show up in the drop down oracle and sun(not my class path).当我尝试它时,只有两个选项出现在下拉 oracle 和 sun(不是我的类路径)中。 I then tried to mark the src folder as source root which helped make the DemoApplication visible by the spring boot configuration然后我尝试将 src 文件夹标记为源根目录,这有助于使 DemoApplication 通过 spring boot 配置可见在此处输入图片说明

Any help on where to go next would greatly be appreciated.任何关于下一步去哪里的帮助将不胜感激。

here is my folder structure that was generated by the spring boot initializr.这是我的文件夹结构,由 spring boot initializr 生成。 only thing i changed was making src the source root.我唯一改变的是使 src 成为源根。

在此处输入图片说明

    <?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.mentor</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>2.0.0.BUILD-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <start-class>com.</start-class>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>


</project>

在此处输入图片说明

Right click the pom.xml file and select 'Add as Maven' The icon on your pom.xml file should look like that:右键单击 pom.xml 文件并选择“添加为 Maven” pom.xml 文件上的图标应如下所示:

enter image description here在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM