简体   繁体   English

Spring-Starter pom.xml找不到应用程序启动类

[英]Spring-Starter pom.xml cannot find Application start class

I am new to spring and trying to write a pom.xml file to be executed with mvn exec:java . 我刚接触Spring,并尝试编写要使用mvn exec:java执行的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.satisfeet</groupId>
    <artifactId>app</artifactId>
    <version>0.0.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.7.RELEASE</version>
    </parent>

    <properties>
        <start-class>com.satisfeet.Application</start-class>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

My directory structure is: 我的目录结构是:

/src
  |_ /main
      |__ /java
           |__ /com
                |__ /satisfeet
                     |__ /core
                     |__ /http
                     |__ Application.java

When I now run mvn package or mvn exec:java I get first a warning: 当我现在运行mvn packagemvn exec:java我首先得到一个警告:

java.lang.ClassNotFoundException: com.satisfeet.Application
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
    at java.lang.Thread.run(Thread.java:745)

which then results in: 然后导致:

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project app: An exception occured while executing the Java class. com.satisfeet.Application -> [Help 1]

which I do not understand as the Application.java file should be correct: 我不理解,因为Application.java文件应该正确:

package com.satisfeet;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;

import com.satisfeet.http.CustomerController;

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

What did I miss? 我错过了什么?

Have a look at Spring docs about how to use the @ComponentScan - you should give it param, which is the package you want Spring to scan. 看看有关如何使用@ComponentScan的Spring文档 -您应该给它param,这是Spring想要扫描的软件包。

package com.satisfeet;

@Configuration
@ComponentScan("com.satisfeet")
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

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

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