Spring Maven项目 - java.lang.IllegalArgumentException:源不能为空

时间:2018-03-18 09:46:22

标签: spring maven spring-boot

我正在尝试启动Spring Boot应用程序,但它无法启动。这是我的堆栈跟踪:

11:27:59.772 [main] DEBUG 
org.springframework.boot.devtools.settings.DevToolsSettings - Included 
patterns for restart : []
11:27:59.775 [main] DEBUG 
org.springframework.boot.devtools.settings.DevToolsSettings - Excluded 
patterns for restart : [/spring-boot-starter/target/classes/, /spring- 
boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, 
 /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, 
 /spring-boot-devtools/target/classes/]
11:27:59.776 [main] DEBUG 
org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs 
for reloading : [file:/C:/Users/Bobi/Documents/workspace-sts- 
3.9.2.RELEASE/springproject/target/classes/]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::             (v2.0.0.M7)

2018-03-18 11:28:00.308  INFO 5048 --- [  restartedMain] 
o.s.boot.SpringApplication               : Starting SpringApplication 
v2.0.0.M7 on DESKTOP-MFS6ORP with PID 5048 
(C:\Users\Bobi\.m2\repository\org\springframework\boot\spring- 
boot\2.0.0.M7\spring-boot-2.0.0.M7.jar started by Bobi in 
C:\Users\Bobi\Documents\workspace-sts-3.9.2.RELEASE\springproject)
2018-03-18 11:28:00.313  INFO 5048 --- [  restartedMain] 
o.s.boot.SpringApplication               : No active profile set, falling 
back to default profiles: default
2018-03-18 11:28:01.410 ERROR 5048 --- [  restartedMain] 
o.s.boot.SpringApplication               : Application startup failed

java.lang.IllegalArgumentException: Sources must not be empty
at org.springframework.util.Assert.notEmpty(Assert.java:450) ~[spring- 
core-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:381) [spring-boot-2.0.0.M7.jar:2.0.0.M7]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:325) [spring-boot-2.0.0.M7.jar:2.0.0.M7]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M7.jar:2.0.0.M7]
at org.springframework.boot.SpringApplication.main(SpringApplication.java:1261) [spring-boot-2.0.0.M7.jar:2.0.0.M7]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher 
.java:49) [spring-boot-devtools-2.0.0.M7.jar:2.0.0.M7]

这是我的主要课程:

package com.example.a;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App  
{
    public static void main( String[] args )
    {
        SpringApplication.run(App.class, args);
    }
}

这是我的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>a</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>a</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

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

我正在使用Spring Tool Suite,我通过File-&gt; New-&gt; Maven Project创建了项目。我添加了一些依赖项,并在主类中添加了SpringApplication.run(App.class, args);行,这就是它。 我在StackOverflow上尝试了其他类似的建议,但对我没什么用。为了让应用程序正确启动,我该怎么做或更改?

2 个答案:

答案 0 :(得分:1)

我解决了这个问题。我以前不知道我是如何运行该项目的,但我刚刚进行了右键单击 - >运行As-&gt; Spring Boot应用程序,它运行正常。

答案 1 :(得分:0)

在 Eclipse 中,当我将它作为 Spring Boot 应用程序运行时,它显示了错误,但是当我将它作为 Java 应用程序从右键单击 -> 运行为 -> Java 应用程序运行时,它完全正常。

>