我正在尝试使用 Spring Native 构建并运行我的 Spring Boot 3.3.5 项目。
依赖关系:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
插件:
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>paketobuildpacks/builder-jammy-buildpackless-tiny</builder>
<buildpacks>
<buildpack>paketobuildpacks/oracle</buildpack>
<buildpack>paketobuildpacks/java-native-image</buildpack>
</buildpacks>
</image>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
配置:
server:
port: 8080
shutdown: graceful
spring:
main:
web-application-type: servlet
应用类别:
@SpringBootApplication
public class ChatbotMemberEventWorkerApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ChatbotMemberEventWorkerApplication.class, args);
}
}
Dockerfile:
FROM ghcr.io/graalvm/graalvm-community:latest as builder
COPY . /artifact
WORKDIR /artifact
RUN microdnf -y install wget unzip zip findutils tar maven
RUN mvn -Pnative native:compile
FROM container-registry.oracle.com/os/oraclelinux:9-slim
EXPOSE 8080
COPY --from=builder /artifact/target/chatbot-member-event-worker ./chatbot-member-event-worker
ENTRYPOINT ["./chatbot-member-event-worker --spring.profiles.active=local"]
当我运行应用程序时,应用程序启动但立即退出。看起来网络服务器实际上并未运行。
日志输出:
INFO 39222 --- [chatbot-member-event-worker] .g.c.ChatbotMemberEventWorkerApplication : Starting AOT-processed ChatbotMemberEventWorkerApplication...
INFO 39222 --- [chatbot-member-event-worker] .g.c.ChatbotMemberEventWorkerApplication : The following 1 profile is active: "local"
Web application could not be started as there was no org.springframework.boot.web.servlet.server.ServletWebServerFactory bean defined in the context.
)
对于为什么会发生这种情况或者如何保持服务器运行有什么见解吗?谢谢!
原来与
有关spring-cloud-starter-bootstrap dependency,当我删除它时,我已经成功了