Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TheBlindM opened this issue Apr 29, 2024 · 13 comments
Closed
Assignees
Labels
type: documentation A documentation update
Milestone

Comments

@TheBlindM
Copy link

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  [�[35mmain�[0;39m] �[36mc.t.t.TShellServerApplication�[0;39m : 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 [�[35mmain�[0;39m] �[36mc.t.t.TShellServerApplication�[0;39m : Running with Spring Boot v3.2.1, Spring v6.1.2
2024/04/29 11:20:41.526 INFO  [�[35mmain�[0;39m] �[36mc.t.t.TShellServerApplication�[0;39m : No active profile set, falling back to 1 default profile: "default"
2024/04/29 11:20:42.527 INFO  [�[35mmain�[0;39m] �[36mo.s.d.r.c.RepositoryConfigurationDelegate�[0;39m : Multiple Spring Data modules found, entering strict repository configuration mode
2024/04/29 11:20:42.531 INFO  [�[35mmain�[0;39m] �[36mo.s.d.r.c.RepositoryConfigurationDelegate�[0;39m : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2024/04/29 11:20:42.559 INFO  [�[35mmain�[0;39m] �[36mo.s.d.r.c.RepositoryConfigurationDelegate�[0;39m : Finished Spring Data repository scanning in 15 ms. Found 0 Redis repository interfaces.
2024/04/29 11:20:43.404 INFO  [�[35mmain�[0;39m] �[36mo.s.b.w.e.t.TomcatWebServer�[0;39m : Tomcat initialized with port 10211 (http)
2024/04/29 11:20:43.425 INFO  [�[35mmain�[0;39m] �[36mo.a.c.c.StandardService�[0;39m : Starting service [Tomcat]
2024/04/29 11:20:43.425 INFO  [�[35mmain�[0;39m] �[36mo.a.c.c.StandardEngine�[0;39m : Starting Servlet engine: [Apache Tomcat/10.1.17]
2024/04/29 11:20:43.479 INFO  [�[35mmain�[0;39m] �[36mo.a.c.c.C.[.[.[/]�[0;39m : Initializing Spring embedded WebApplicationContext
2024/04/29 11:20:43.480 INFO  [�[35mmain�[0;39m] �[36mo.s.b.w.s.c.ServletWebServerApplicationContext�[0;39m : Root WebApplicationContext: initialization completed in 1858 ms
2024/04/29 11:20:43.900 INFO  [�[35mmain�[0;39m] �[36mc.t.t.c.TShellConfig�[0;39m : Asura cache store 鍔犺浇瀹炵幇 : [class com.theblind.tshellserver.common.cache.RedisCacheStore]
2024/04/29 11:20:44.038 WARN  [�[35mmain�[0;39m] �[36mo.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext�[0;39m : 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  [�[35mmain�[0;39m] �[36mo.a.c.c.StandardService�[0;39m : Stopping service [Tomcat]
2024/04/29 11:20:44.086 INFO  [�[35mmain�[0;39m] �[36mo.s.b.a.l.ConditionEvaluationReportLogger�[0;39m :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024/04/29 11:20:44.126 ERROR [�[35mmain�[0;39m] �[36mo.s.b.d.LoggingFailureAnalysisReporter�[0;39m :

***************************
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).

image

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 29, 2024
@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 29, 2024
@mhalbritter
Copy link
Contributor

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

@wilkinsona
Copy link
Member

wilkinsona commented Apr 29, 2024

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.

@wilkinsona wilkinsona reopened this Apr 29, 2024
@wilkinsona wilkinsona changed the title Spring boot Docker Compose cannot be used after packaging Note the spring-boot-docker-compose is excluded by default from packaged jars Apr 29, 2024
@wilkinsona wilkinsona added type: documentation A documentation update and removed status: duplicate A duplicate of another issue labels Apr 29, 2024
@mhalbritter mhalbritter added this to the 3.1.x milestone Apr 29, 2024
@mhalbritter mhalbritter self-assigned this Apr 29, 2024
@wilkinsona wilkinsona changed the title Note the spring-boot-docker-compose is excluded by default from packaged jars Note that spring-boot-docker-compose is excluded by default from packaged jars Apr 29, 2024
@TheBlindM
Copy link
Author

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

@mhalbritter
Copy link
Contributor

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>

@TheBlindM
Copy link
Author

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

@mhalbritter
Copy link
Contributor

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.

@TheBlindM
Copy link
Author

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](https://docs.spring.io/spring-boot/docs/3.1.0/reference/html/features.html#features.docker-compose)

@mhalbritter
Copy link
Contributor

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

@purbarunc
Copy link

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.

@wilkinsona
Copy link
Member

@purbarunc
Copy link

@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.

@wilkinsona
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

5 participants