如果你修改了 Spring Boot 的启动器类名,可能会导致应用程序无法找到该类,从而无法启动。这时候,你需要修改一些配置文件以告诉 Spring Boot 新的启动器类名。

  1. 修改 pom.xml 文件

如果你使用 Maven 构建项目,你需要修改 pom.xml 文件中的 <mainClass> 元素。将其值设置为新的启动器类名。例如,如果你的启动器类名为 com.example.MySpringBootApplication,则需要将 <mainClass> 元素的值设置为 com.example.MySpringBootApplication

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <configuration>
        <mainClass>com.example.MySpringBootApplication</mainClass>
      </configuration>
    </plugin>
  </plugins>
</build>
  1. 修改 application.properties 文件

在 Spring Boot 应用程序中,你还需要修改 application.properties 文件中的 spring.main.sources 属性。将其值设置为新的启动器类名。例如:

spring.main.sources=com.example.MySpringBootApplication
  1. 重新构建应用程序

完成以上步骤后,你需要重新构建应用程序,以使修改生效。如果你使用 Maven 构建项目,可以在项目根目录下运行以下命令:

mvn clean package

这个命令将会重新构建你的应用程序,并在 target 目录下生成一个新的可执行 JAR 文件。

  1. 运行应用程序

最后,你可以使用以下命令运行应用程序:

java -jar target/my-app.jar

其中,my-app.jar 是刚刚生成的 JAR 文件的名称。如果一切正常,你的应用程序应该能够正常启动。

spring Boot 修改了启动器类名 找不到类了

原文地址: https://www.cveoy.top/t/topic/jIT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录