Java spring启动应用程序无法启动
我最近开始使用spring boot,anf开发一个web应用程序,按照官方网站上的指南,设法创建这两个文件:Java spring启动应用程序无法启动,java,spring,spring-mvc,spring-boot,Java,Spring,Spring Mvc,Spring Boot,我最近开始使用spring boot,anf开发一个web应用程序,按照官方网站上的指南,设法创建这两个文件: 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.or
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>spring</groupId>
<artifactId>app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>app</name>
<url>http://maven.apache.org</url>
<properties>
<start-class>com.spring.app.Application</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
但是当我尝试使用java-jarappname
运行应用程序时,我得到了一个错误:找不到主类:com.spring.app.application。程序将退出
,并且在终端中:线程“main”java.lang.NoClassDefFoundError中的异常:com/spring/app/Application
我做错了什么?在pom.xml中有两件事要做 首先将start类更改为应用程序类。 其次,将超级酷的Spring Boot maven builder添加到pom中 大概是这样的:
<?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.sample</groupId>
<artifactId>beanlist</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<start-class>com.sample.Application</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project
4.0.0
com.sample
豆名单
1.0-快照
com.sample.Application
UTF-8
org.springframework.boot
spring启动程序父级
1.1.8.发布
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
springbootmaven插件
应更改以下标记的值,以使实类和main方法匹配。尝试指定正确的软件包并运行“mvn安装”
com.sample.Application
您的应用程序在此软件包中:
package com.spring.app;
这意味着您的应用程序完整路径应该是package com.spring.app.Application,错误代码为com.spring.Application
未找到。
也许你应该检查一下你的跑步配置,我也遇到了同样的错误。通过在eclipse中将项目转换为maven解决了这个问题,如下图所示:
希望你会喜欢。:) 好的,我在pom.xml中尝试了这个修改(其他文件保持不变),但仍然得到了相同的错误。嗯,对我来说效果很好。对正确的包名进行三次检查。这应该是您的应用程序类,而不是“com.spring.app.application”。如果只有一个类具有main方法,spring boot应该能够检测开始类本身。最重要的部分是添加spring boot maven插件。@M.Deinum humm,我现在的项目中只有两个类:Application.java,我在其中放置主方法,还有一个名为HelloController。在我的pom.xml中,我将类的完整路径(包括包)放在start类中。我只尝试使用类的名称,但也不起作用。你不需要插件就能找到类。把它拿走。。。导入部分是spring引导插件和父插件。是的,标记具有正确的值:com.spring.app.Application
。
<?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.sample</groupId>
<artifactId>beanlist</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<start-class>com.sample.Application</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project
<start-class>com.sample.Application</start-class>