Spring Boot-ClassNotFoundException,但是主类存在

时间:2019-03-11 22:39:21

标签: java spring maven spring-boot jsp

我正在阅读一个教程,以从Spring Boot运行JSP。即使存在我指定为主类的类,我也得到了此错误跟踪。这是我已为空间编辑的异常跟踪。

   java.lang.ClassNotFoundException: com.hellokoding.springboot.view.Application
        at java.net.URLClassLoader.findClass (URLClassLoader.java:471)
        at java.lang.ClassLoader.loadClass (ClassLoader.java:588)
        at java.lang.ClassLoader.loadClass (ClassLoader.java:521)
        at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:553)
        at java.lang.Thread.run (Thread.java:834)

这是我的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.hellokoding.springboot</groupId>
    <artifactId>jsp-helloworld</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.hellokoding.springboot.view.Application</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

1 个答案:

答案 0 :(得分:1)

通过扩展生成的工件来确认文件已在预期位置编译。您应该在以下位置看到Application.class文件:

/target/ROOT/WEB-INF/classes/com/hellokoding/springboot/view/Application.class

应使用@SpringBootApplication进行注释,其中包含以下方法签名

public static void main(String [] args)