Изучаю основы spring и написал простой код:
@SpringBootApplication
@EnableAsync
public class main
{
public static void main(String[] args)
{
SpringApplication.run(main.class);
}
}
Если запустить из IDE(Intellij 2025), то можно увидеть, что сервер Tomcat загружается:
2026-04-14T00:46:26.530+03:00 INFO 20496 --- [ main] Myapp.main : Starting main using Java 23 with PID 20496 (J:\spring_web\build\classes\java\main started by kuk in J:\spring_web)
2026-04-14T00:46:26.532+03:00 INFO 20496 --- [ main] Myapp.main : No active profile set, falling back to 1 default profile: "default"
2026-04-14T00:46:27.211+03:00 INFO 20496 --- [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat initialized with port 8843 (https)
2026-04-14T00:46:27.224+03:00 INFO 20496 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2026-04-14T00:46:27.225+03:00 INFO 20496 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/11.0.20]
2026-04-14T00:46:27.265+03:00 INFO 20496 --- [ main] b.w.c.s.WebApplicationContextInitializer : Root WebApplicationContext: initialization completed in 686 ms
2026-04-14T00:46:27.667+03:00 INFO 20496 --- [ main] o.a.t.util.net.NioEndpoint.certificate : Connector [https-jsse-nio-8843], TLS virtual host [_default_], certificate type [UNDEFINED] configured from keystore [Set directly - location unknown] using alias [myapp] with trust store [null]
2026-04-14T00:46:27.680+03:00 INFO 20496 --- [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat started on port 8843 (https) with context path '/'
2026-04-14T00:46:27.685+03:00 INFO 20496 --- [ main] Myapp.main : Started main in 1.462 seconds (process running for 1.766)
Когда я собираю JAR файл и запускаю через java -jar myapp.jar, то сервер не запускается и приложение просто закрывается:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v4.0.5)
00:51:00.938 [main] INFO Myapp.main -- Starting main using Java 23.0.2 with PID 3572 (J:\spring_web\myapp.jar started by kuk in J:\spring_web)
00:51:00.939 [main] INFO Myapp.main -- No active profile set, falling back to 1 default profile: "default"
00:51:01.301 [main] INFO Myapp.main -- Started main in 0.5 seconds (process running for 0.751)
Порт я проверял, он свободен перед запуском. Для сборки я использую Gradle 8 и прописал там такое:
plugins {
id 'org.springframework.boot' version '4.0.5'
id 'io.spring.dependency-management' version '1.1.7'
id 'java'
}
dependencies {
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot:4.0.5'
implementation 'org.springframework.boot:spring-boot-autoconfigure:4.0.5'
implementation 'org.springframework.boot:spring-boot-starter-web:4.0.5'
compileOnly 'org.springframework.boot:spring-boot-starter-tomcat:4.0.5'
implementation 'org.springframework.boot:spring-boot-gradle-plugin:4.0.5'
}
Вроде всё должно работать, но почему-то не работает. Я не смог отыскать такой же минимальный пример, на котором бы запускался встроенный Tomcat сервер. Может надо что-то ещё указать?
З.Ы Я убрал строчку compileOnly 'org.springframework.boot:spring-boot-starter-tomcat:4.0.5' и ничего не поменялось :( Сервер также не стартует, и никаких ошибок не сообщает в консоли