Starting normally in idea, but failing to run Java jar after packaging

C:\Users\bangfu\.jdks\openjdk-21.0.1\bin>java.exe -jar E:\study\T-Shell-Server\target\新建文件夹\T-Shell-Server-0.0.1-SNAPSHOT.jar 

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.2.1)

2024/04/29 11:20:41.523 INFO  [main] c.t.t.TShellServerApplication : Starting TShellServerApplication using Java 21.0.1 with PID 27452 (E:\study\T-Shell-Server\target\鏂板缓鏂囦欢澶筡T-Shell-Server-0.0.1-SNAPSHOT.jar started by bangfu in C:\Users\bangfu\.jdks\openjdk-21.0.1\bin)
2024/04/29 11:20:41.525 DEBUG [main] c.t.t.TShellServerApplication : Running with Spring Boot v3.2.1, Spring v6.1.2
2024/04/29 11:20:41.526 INFO  [main] c.t.t.TShellServerApplication : No active profile set, falling back to 1 default profile: "default"
2024/04/29 11:20:42.527 INFO  [main] o.s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2024/04/29 11:20:42.531 INFO  [main] o.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2024/04/29 11:20:42.559 INFO  [main] o.s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 15 ms. Found 0 Redis repository interfaces.
2024/04/29 11:20:43.404 INFO  [main] o.s.b.w.e.t.TomcatWebServer : Tomcat initialized with port 10211 (http)
2024/04/29 11:20:43.425 INFO  [main] o.a.c.c.StandardService : Starting service [Tomcat]
2024/04/29 11:20:43.425 INFO  [main] o.a.c.c.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.17]
2024/04/29 11:20:43.479 INFO  [main] o.a.c.c.C.[.[.[/] : Initializing Spring embedded WebApplicationContext
2024/04/29 11:20:43.480 INFO  [main] o.s.b.w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1858 ms
2024/04/29 11:20:43.900 INFO  [main] c.t.t.c.TShellConfig : Asura cache store 鍔犺浇瀹炵幇 : [class com.theblind.tshellserver.common.cache.RedisCacheStore]
2024/04/29 11:20:44.038 WARN  [main] o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController' defined in URL [jar:nested:/E:/study/T-Shell-Server/target/鏂板缓鏂囦欢澶?T-Shell-Server-0.0.1-SNAPSHOT.jar/!BOOT-INF/classes/!/com/theblind/tshellserver/controller/UserController.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'userServiceImpl' defined in URL [jar:nested:/E:/study/T-Shell-Server/target/鏂板缓鏂囦欢澶?T-Shell-Server-0.0.1-SNAPSHOT.jar/!BOOT-INF/classes/!/com/theblind/tshellserver/service/impl/UserServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 3: Error creating bean with name 'syncDataMapper' defined in URL [jar:nested:/E:/study/T-Shell-Server/target/鏂板缓鏂囦欢澶?T-Shell-Server-0.0.1-SNAPSHOT.jar/!BOOT-INF/classes/!/com/theblind/tshellserver/mapper/SyncDataMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Failed to determine a suitable driver class
s
2024/04/29 11:20:44.063 INFO  [main] o.a.c.c.StandardService : Stopping service [Tomcat]
2024/04/29 11:20:44.086 INFO  [main] o.s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024/04/29 11:20:44.126 ERROR [main] o.s.b.d.LoggingFailureAnalysisReporter :

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
        If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
        If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

SpringBoot Note that spring-boot-docker-compose is excluded by default from packaged jars

Comment From: wilkinsona

The compose.yaml is loaded from the working directory. You either need to move it or run your application from a different directory. Duplicates #40512.

Comment From: mhalbritter

Additionally, the docker compose support is excluded from the built JAR file, as documented here.

Comment From: wilkinsona

Good point, @mhalbritter. Thanks. I think that part of it had slipped my mind. Let's add a note to the reference documentation similar to the one that we already have for Devtools.

Comment From: TheBlindM

Good point, @mhalbritter. Thanks. I think that part of it had slipped my mind. Let's add a note to the reference documentation similar to the one that we already have for Devtools.

Sorry, I'm still not quite sure. If I want to start Java jar, what should I do

Comment From: mhalbritter

If you want to include docker compose support in the Uber JAR, set excludeDockerCompose in the spring-boot-maven-plugin configuration to false.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <excludeDockerCompose>false</excludeDockerCompose>
            </configuration>
        </plugin>
    </plugins>
</build>

Comment From: TheBlindM

I have found it, thank you. Just setfalse. Why exclude spring boot Docker Compose?

Comment From: mhalbritter

Because it's intended as a development time feature. When using the JAR, you're usually deploying it somewhere, and there you don't usually use docker compose to provide the databases, etc.

Comment From: TheBlindM

Because it's intended as a development time feature. When using the JAR, you're usually deploying it somewhere, and there you don't usually use docker compose to provide the databases, etc.

Understood, thank you. But it should be explained in the document 😂 [https://docs.spring.io/spring-boot/docs/3.1.0/reference/html/features.html#features.docker-compose](url)

Comment From: mhalbritter

That's what we're using this issue for :)

Comment From: purbarunc

If you want to include docker compose support in the Uber JAR, set excludeDockerCompose in the spring-boot-maven-plugin configuration to false.

<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludeDockerCompose>false</excludeDockerCompose> </configuration> </plugin> </plugins> </build>

@mhalbritter Is this for maven? what should I do if its a gradle project. Can we have a similar configuration for gradle in build.gradle.

Comment From: wilkinsona

@purbarunc please read the documentation update that was made to close this issue. It links to https://docs.spring.io/spring-boot/gradle-plugin/packaging.html#packaging-executable.configuring.including-development-only-dependencies.

Comment From: purbarunc

@purbarunc please read the documentation update that was made to close this issue. It links to https://docs.spring.io/spring-boot/gradle-plugin/packaging.html#packaging-executable.configuring.including-development-only-dependencies.

I have read this already, but I am not able to get what should be the equivalent configuration for <excludeDockerCompose>false</excludeDockerCompose> groovy/gradle.

Comment From: wilkinsona

It's described in the docs. First, you should have the dependency in the developmentOnly configuration:

dependencies {
    developmentOnly("org.springframework.boot:spring-boot-docker-compose")
}

Then you need to include this configuration in the classpath of the bootJar task:

tasks.named("bootJar") {
    classpath configurations.developmentOnly
}

If you have any further questions, please follow up on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.