mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Polish
This commit is contained in:
parent
595fc13b34
commit
ae90add7c7
@ -22,6 +22,7 @@ import java.util.Collection;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@ -37,6 +38,7 @@ import org.springframework.aot.hint.MemberCategory;
|
|||||||
import org.springframework.aot.hint.RuntimeHints;
|
import org.springframework.aot.hint.RuntimeHints;
|
||||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||||
import org.springframework.aot.hint.TypeHint;
|
import org.springframework.aot.hint.TypeHint;
|
||||||
|
import org.springframework.aot.hint.TypeHint.Builder;
|
||||||
import org.springframework.aot.hint.TypeReference;
|
import org.springframework.aot.hint.TypeReference;
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
@ -250,19 +252,16 @@ class HibernateJpaConfiguration extends JpaBaseConfiguration {
|
|||||||
|
|
||||||
static class HibernateRuntimeHints implements RuntimeHintsRegistrar {
|
static class HibernateRuntimeHints implements RuntimeHintsRegistrar {
|
||||||
|
|
||||||
|
private static final Consumer<Builder> INVOKE_DECLARED_CONSTRUCTORS = TypeHint
|
||||||
|
.builtWith(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||||
for (String clazz : NO_JTA_PLATFORM_CLASSES) {
|
for (String noJtaPlatformClass : NO_JTA_PLATFORM_CLASSES) {
|
||||||
hints.reflection()
|
hints.reflection().registerType(TypeReference.of(noJtaPlatformClass), INVOKE_DECLARED_CONSTRUCTORS);
|
||||||
.registerType(TypeReference.of(clazz),
|
|
||||||
TypeHint.builtWith(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
|
|
||||||
}
|
}
|
||||||
hints.reflection()
|
hints.reflection().registerType(SpringImplicitNamingStrategy.class, INVOKE_DECLARED_CONSTRUCTORS);
|
||||||
.registerType(SpringImplicitNamingStrategy.class,
|
hints.reflection().registerType(CamelCaseToUnderscoresNamingStrategy.class, INVOKE_DECLARED_CONSTRUCTORS);
|
||||||
TypeHint.builtWith(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
|
|
||||||
hints.reflection()
|
|
||||||
.registerType(CamelCaseToUnderscoresNamingStrategy.class,
|
|
||||||
TypeHint.builtWith(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -487,10 +487,11 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes
|
|||||||
void registersHintsForJtaClasses() {
|
void registersHintsForJtaClasses() {
|
||||||
RuntimeHints hints = new RuntimeHints();
|
RuntimeHints hints = new RuntimeHints();
|
||||||
new HibernateRuntimeHints().registerHints(hints, getClass().getClassLoader());
|
new HibernateRuntimeHints().registerHints(hints, getClass().getClassLoader());
|
||||||
for (String clazz : Arrays.asList("org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform",
|
for (String noJtaPlatformClass : Arrays.asList(
|
||||||
|
"org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform",
|
||||||
"org.hibernate.service.jta.platform.internal.NoJtaPlatform")) {
|
"org.hibernate.service.jta.platform.internal.NoJtaPlatform")) {
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onType(TypeReference.of(clazz))
|
.onType(TypeReference.of(noJtaPlatformClass))
|
||||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(hints);
|
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(hints);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -499,10 +500,10 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes
|
|||||||
void registersHintsForNamingClasses() {
|
void registersHintsForNamingClasses() {
|
||||||
RuntimeHints hints = new RuntimeHints();
|
RuntimeHints hints = new RuntimeHints();
|
||||||
new HibernateRuntimeHints().registerHints(hints, getClass().getClassLoader());
|
new HibernateRuntimeHints().registerHints(hints, getClass().getClassLoader());
|
||||||
for (Class<?> clazz : Arrays.asList(SpringImplicitNamingStrategy.class,
|
for (Class<?> noJtaPlatformClass : Arrays.asList(SpringImplicitNamingStrategy.class,
|
||||||
CamelCaseToUnderscoresNamingStrategy.class)) {
|
CamelCaseToUnderscoresNamingStrategy.class)) {
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onType(clazz)
|
.onType(noJtaPlatformClass)
|
||||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(hints);
|
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(hints);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import org.springframework.context.ApplicationContext;
|
|||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.context.event.SimpleApplicationEventMulticaster;
|
import org.springframework.context.event.SimpleApplicationEventMulticaster;
|
||||||
import org.springframework.core.log.LogMessage;
|
import org.springframework.core.log.LogMessage;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the lifecycle for docker compose services.
|
* Manages the lifecycle for docker compose services.
|
||||||
@ -125,11 +126,8 @@ class DockerComposeLifecycleManager {
|
|||||||
protected DockerComposeFile getComposeFile() {
|
protected DockerComposeFile getComposeFile() {
|
||||||
DockerComposeFile composeFile = (this.properties.getFile() != null)
|
DockerComposeFile composeFile = (this.properties.getFile() != null)
|
||||||
? DockerComposeFile.of(this.properties.getFile()) : DockerComposeFile.find(this.workingDirectory);
|
? DockerComposeFile.of(this.properties.getFile()) : DockerComposeFile.find(this.workingDirectory);
|
||||||
if (composeFile == null) {
|
Assert.state(composeFile != null, () -> "No Docker Compose file found in directory '%s'".formatted(
|
||||||
File dir = (this.workingDirectory != null) ? this.workingDirectory : new File(".");
|
((this.workingDirectory != null) ? this.workingDirectory : new File(".")).toPath().toAbsolutePath()));
|
||||||
throw new IllegalStateException("No Docker Compose file found in directory '%s'"
|
|
||||||
.formatted(dir.toPath().toAbsolutePath().toString()));
|
|
||||||
}
|
|
||||||
logger.info(LogMessage.format("Using Docker Compose file '%s'", composeFile));
|
logger.info(LogMessage.format("Using Docker Compose file '%s'", composeFile));
|
||||||
return composeFile;
|
return composeFile;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
[[deployment.efficient]]
|
[[deployment.efficient]]
|
||||||
== Efficient deployments
|
== Efficient deployments
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[deployment.efficient.unpacking]]
|
[[deployment.efficient.unpacking]]
|
||||||
=== Unpacking the Executable JAR
|
=== Unpacking the Executable JAR
|
||||||
If you are running your application from a container, you can use an executable jar, but it is also often an advantage to explode it and run it in a different way.
|
If you are running your application from a container, you can use an executable jar, but it is also often an advantage to explode it and run it in a different way.
|
||||||
@ -28,6 +30,8 @@ Once you have unpacked the jar file, you can also get an extra boost to startup
|
|||||||
NOTE: Using the `JarLauncher` over the application's main method has the added benefit of a predictable classpath order.
|
NOTE: Using the `JarLauncher` over the application's main method has the added benefit of a predictable classpath order.
|
||||||
The jar contains a `classpath.idx` file which is used by the `JarLauncher` when constructing the classpath.
|
The jar contains a `classpath.idx` file which is used by the `JarLauncher` when constructing the classpath.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[deployment.efficient.aot]]
|
[[deployment.efficient.aot]]
|
||||||
=== Using Ahead-of-time Processing With the JVM
|
=== Using Ahead-of-time Processing With the JVM
|
||||||
|
|
||||||
|
@ -1083,9 +1083,9 @@ TIP: You can use the `@ServiceConnection` annotation on `Container` fields to es
|
|||||||
You can also add <<features#features.testing.testcontainers.dynamic-properties,`@DynamicPropertySource` annotated methods>> to your declaration class.
|
You can also add <<features#features.testing.testcontainers.dynamic-properties,`@DynamicPropertySource` annotated methods>> to your declaration class.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[features.testing.testcontainers.at-development-time.devtools]]
|
[[features.testing.testcontainers.at-development-time.devtools]]
|
||||||
===== Using DevTools with Testcontainers at Development Time
|
===== Using DevTools with Testcontainers at Development Time
|
||||||
|
|
||||||
When using devtools, you can annotate beans and bean methods with `@RestartScope`.
|
When using devtools, you can annotate beans and bean methods with `@RestartScope`.
|
||||||
Such beans won't be recreated when the devtools restart the application.
|
Such beans won't be recreated when the devtools restart the application.
|
||||||
This is especially useful for Testcontainer `Container` beans, as they keep their state despite the application restart.
|
This is especially useful for Testcontainer `Container` beans, as they keep their state despite the application restart.
|
||||||
@ -1095,6 +1095,8 @@ include::code:MyContainersConfiguration[]
|
|||||||
WARNING: If you're using Gradle and want to use this feature, you need to change the configuration of the `spring-boot-devtools` dependency from `developmentOnly` to `testImplementation`.
|
WARNING: If you're using Gradle and want to use this feature, you need to change the configuration of the `spring-boot-devtools` dependency from `developmentOnly` to `testImplementation`.
|
||||||
With the default scope of `developmentOnly`, the `bootTestRun` task will not pick up changes in your code, as the devtools are not active.
|
With the default scope of `developmentOnly`, the `bootTestRun` task will not pick up changes in your code, as the devtools are not active.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[features.testing.utilities]]
|
[[features.testing.utilities]]
|
||||||
=== Test Utilities
|
=== Test Utilities
|
||||||
A few test utility classes that are generally useful when testing your application are packaged as part of `spring-boot`.
|
A few test utility classes that are generally useful when testing your application are packaged as part of `spring-boot`.
|
||||||
|
@ -13,9 +13,10 @@ Doing so generates a new project structure so that you can <<getting-started#get
|
|||||||
Check the https://github.com/spring-io/start.spring.io/blob/main/USING.adoc[start.spring.io user guide] for more details.
|
Check the https://github.com/spring-io/start.spring.io/blob/main/USING.adoc[start.spring.io user guide] for more details.
|
||||||
====
|
====
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.prerequisites]]
|
[[getting-started.first-application.prerequisites]]
|
||||||
=== Prerequisites
|
=== Prerequisites
|
||||||
|
|
||||||
Before we begin, open a terminal and run the following commands to ensure that you have a valid version of Java installed:
|
Before we begin, open a terminal and run the following commands to ensure that you have a valid version of Java installed:
|
||||||
|
|
||||||
[source,shell,indent=0,subs="verbatim"]
|
[source,shell,indent=0,subs="verbatim"]
|
||||||
@ -30,9 +31,9 @@ NOTE: This sample needs to be created in its own directory.
|
|||||||
Subsequent instructions assume that you have created a suitable directory and that it is your current directory.
|
Subsequent instructions assume that you have created a suitable directory and that it is your current directory.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.prerequisites.maven]]
|
[[getting-started.first-application.prerequisites.maven]]
|
||||||
==== Maven
|
==== Maven
|
||||||
|
|
||||||
If you want to use Maven, ensure that you have Maven installed:
|
If you want to use Maven, ensure that you have Maven installed:
|
||||||
|
|
||||||
[source,shell,indent=0,subs="verbatim"]
|
[source,shell,indent=0,subs="verbatim"]
|
||||||
@ -43,30 +44,32 @@ If you want to use Maven, ensure that you have Maven installed:
|
|||||||
Java version: 17.0.4.1, vendor: BellSoft, runtime: /Users/developer/sdkman/candidates/java/17.0.4.1-librca
|
Java version: 17.0.4.1, vendor: BellSoft, runtime: /Users/developer/sdkman/candidates/java/17.0.4.1-librca
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.prerequisites.gradle]]
|
[[getting-started.first-application.prerequisites.gradle]]
|
||||||
==== Gradle
|
==== Gradle
|
||||||
|
|
||||||
If you want to use Gradle, ensure that you have Gradle installed:
|
If you want to use Gradle, ensure that you have Gradle installed:
|
||||||
|
|
||||||
[source,shell,indent=0,subs="verbatim"]
|
[source,shell,indent=0,subs="verbatim"]
|
||||||
----
|
----
|
||||||
$ gradle --version
|
$ gradle --version
|
||||||
|
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
Gradle 8.1.1
|
Gradle 8.1.1
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
|
|
||||||
Build time: 2023-04-21 12:31:26 UTC
|
Build time: 2023-04-21 12:31:26 UTC
|
||||||
Revision: 1cf537a851c635c364a4214885f8b9798051175b
|
Revision: 1cf537a851c635c364a4214885f8b9798051175b
|
||||||
|
|
||||||
Kotlin: 1.8.10
|
Kotlin: 1.8.10
|
||||||
Groovy: 3.0.15
|
Groovy: 3.0.15
|
||||||
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
|
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
|
||||||
JVM: 17.0.7 (BellSoft 17.0.7+7-LTS)
|
JVM: 17.0.7 (BellSoft 17.0.7+7-LTS)
|
||||||
OS: Linux 6.2.12-200.fc37.aarch64 aarch64
|
OS: Linux 6.2.12-200.fc37.aarch64 aarch64
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.pom]]
|
[[getting-started.first-application.pom]]
|
||||||
=== Setting up the project with Maven
|
=== Setting up the project with Maven
|
||||||
We need to start by creating a Maven `pom.xml` file.
|
We need to start by creating a Maven `pom.xml` file.
|
||||||
@ -125,35 +128,36 @@ You can test it by running `mvn package` (for now, you can ignore the "`jar will
|
|||||||
NOTE: At this point, you could import the project into an IDE (most modern Java IDEs include built-in support for Maven).
|
NOTE: At this point, you could import the project into an IDE (most modern Java IDEs include built-in support for Maven).
|
||||||
For simplicity, we continue to use a plain text editor for this example.
|
For simplicity, we continue to use a plain text editor for this example.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.gradle]]
|
[[getting-started.first-application.gradle]]
|
||||||
=== Setting up the project with Gradle
|
=== Setting up the project with Gradle
|
||||||
|
|
||||||
We need to start by creating a Gradle `build.gradle` file.
|
We need to start by creating a Gradle `build.gradle` file.
|
||||||
The `build.gradle` is the build script that is used to build your project.
|
The `build.gradle` is the build script that is used to build your project.
|
||||||
Open your favorite text editor and add the following:
|
Open your favorite text editor and add the following:
|
||||||
|
|
||||||
[source,gradle,indent=0,subs="verbatim,attributes"]
|
[source,gradle,indent=0,subs="verbatim,attributes"]
|
||||||
----
|
----
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'org.springframework.boot' version '{spring-boot-version}'
|
id 'org.springframework.boot' version '{spring-boot-version}'
|
||||||
id 'io.spring.dependency-management' version '1.1.0'
|
id 'io.spring.dependency-management' version '1.1.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'com.example'
|
group = 'com.example'
|
||||||
version = '0.0.1-SNAPSHOT'
|
version = '0.0.1-SNAPSHOT'
|
||||||
sourceCompatibility = '17'
|
sourceCompatibility = '17'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
ifeval::["{artifact-release-type}" != "release"]
|
ifeval::["{artifact-release-type}" != "release"]
|
||||||
maven { url 'https://repo.spring.io/milestone' }
|
maven { url 'https://repo.spring.io/milestone' }
|
||||||
maven { url 'https://repo.spring.io/snapshot' }
|
maven { url 'https://repo.spring.io/snapshot' }
|
||||||
endif::[]
|
endif::[]
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
The preceding listing should give you a working build.
|
The preceding listing should give you a working build.
|
||||||
@ -162,15 +166,17 @@ You can test it by running `gradle classes`.
|
|||||||
NOTE: At this point, you could import the project into an IDE (most modern Java IDEs include built-in support for Gradle).
|
NOTE: At this point, you could import the project into an IDE (most modern Java IDEs include built-in support for Gradle).
|
||||||
For simplicity, we continue to use a plain text editor for this example.
|
For simplicity, we continue to use a plain text editor for this example.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.dependencies]]
|
[[getting-started.first-application.dependencies]]
|
||||||
=== Adding Classpath Dependencies
|
=== Adding Classpath Dependencies
|
||||||
|
|
||||||
Spring Boot provides a number of "`Starters`" that let you add jars to your classpath.
|
Spring Boot provides a number of "`Starters`" that let you add jars to your classpath.
|
||||||
"`Starters`" provide dependencies that you are likely to need when developing a specific type of application.
|
"`Starters`" provide dependencies that you are likely to need when developing a specific type of application.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.dependencies.maven]]
|
[[getting-started.first-application.dependencies.maven]]
|
||||||
==== Maven
|
==== Maven
|
||||||
|
|
||||||
Most Spring Boot applications use the `spring-boot-starter-parent` in the `parent` section of the POM.
|
Most Spring Boot applications use the `spring-boot-starter-parent` in the `parent` section of the POM.
|
||||||
The `spring-boot-starter-parent` is a special starter that provides useful Maven defaults.
|
The `spring-boot-starter-parent` is a special starter that provides useful Maven defaults.
|
||||||
It also provides a <<using#using.build-systems.dependency-management,`dependency-management`>> section so that you can omit `version` tags for "`blessed`" dependencies.
|
It also provides a <<using#using.build-systems.dependency-management,`dependency-management`>> section so that you can omit `version` tags for "`blessed`" dependencies.
|
||||||
@ -201,9 +207,10 @@ To add the necessary dependencies, edit your `pom.xml` and add the `spring-boot-
|
|||||||
|
|
||||||
If you run `mvn dependency:tree` again, you see that there are now a number of additional dependencies, including the Tomcat web server and Spring Boot itself.
|
If you run `mvn dependency:tree` again, you see that there are now a number of additional dependencies, including the Tomcat web server and Spring Boot itself.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.dependencies.gradle]]
|
[[getting-started.first-application.dependencies.gradle]]
|
||||||
==== Gradle
|
==== Gradle
|
||||||
|
|
||||||
Most Spring Boot applications use the `org.springframework.boot` Gradle plugin.
|
Most Spring Boot applications use the `org.springframework.boot` Gradle plugin.
|
||||||
This plugin provides useful defaults and Gradle tasks.
|
This plugin provides useful defaults and Gradle tasks.
|
||||||
The `io.spring.dependency-management` Gradle plugin provides <<using#using.build-systems.dependency-management, dependency management>> so that you can omit `version` tags for "`blessed`" dependencies.
|
The `io.spring.dependency-management` Gradle plugin provides <<using#using.build-systems.dependency-management, dependency management>> so that you can omit `version` tags for "`blessed`" dependencies.
|
||||||
@ -213,13 +220,13 @@ Before that, we can look at what we currently have by running the following comm
|
|||||||
|
|
||||||
[source,shell,indent=0,subs="verbatim"]
|
[source,shell,indent=0,subs="verbatim"]
|
||||||
----
|
----
|
||||||
$ gradle dependencies
|
$ gradle dependencies
|
||||||
|
|
||||||
> Task :dependencies
|
> Task :dependencies
|
||||||
|
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
Root project 'myproject'
|
Root project 'myproject'
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
----
|
----
|
||||||
|
|
||||||
The `gradle dependencies` command prints a tree representation of your project dependencies.
|
The `gradle dependencies` command prints a tree representation of your project dependencies.
|
||||||
@ -228,14 +235,15 @@ To add the necessary dependencies, edit your `build.gradle` and add the `spring-
|
|||||||
|
|
||||||
[source,gradle,indent=0,subs="verbatim"]
|
[source,gradle,indent=0,subs="verbatim"]
|
||||||
----
|
----
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
If you run `gradle dependencies` again, you see that there are now a number of additional dependencies, including the Tomcat web server and Spring Boot itself.
|
If you run `gradle dependencies` again, you see that there are now a number of additional dependencies, including the Tomcat web server and Spring Boot itself.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.code]]
|
[[getting-started.first-application.code]]
|
||||||
=== Writing the Code
|
=== Writing the Code
|
||||||
To finish our application, we need to create a single Java file.
|
To finish our application, we need to create a single Java file.
|
||||||
@ -296,6 +304,8 @@ The `args` array is also passed through to expose any command-line arguments.
|
|||||||
[[getting-started.first-application.run]]
|
[[getting-started.first-application.run]]
|
||||||
=== Running the Example
|
=== Running the Example
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.run.maven]]
|
[[getting-started.first-application.run.maven]]
|
||||||
==== Maven
|
==== Maven
|
||||||
At this point, your application should work.
|
At this point, your application should work.
|
||||||
@ -329,9 +339,10 @@ If you open a web browser to `http://localhost:8080`, you should see the followi
|
|||||||
|
|
||||||
To gracefully exit the application, press `ctrl-c`.
|
To gracefully exit the application, press `ctrl-c`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.run.gradle]]
|
[[getting-started.first-application.run.gradle]]
|
||||||
==== Gradle
|
==== Gradle
|
||||||
|
|
||||||
At this point, your application should work.
|
At this point, your application should work.
|
||||||
Since you used the `org.springframework.boot` Gradle plugin, you have a useful `bootRun` goal that you can use to start the application.
|
Since you used the `org.springframework.boot` Gradle plugin, you have a useful `bootRun` goal that you can use to start the application.
|
||||||
Type `gradle bootRun` from the root project directory to start the application.
|
Type `gradle bootRun` from the root project directory to start the application.
|
||||||
@ -364,6 +375,7 @@ If you open a web browser to `http://localhost:8080`, you should see the followi
|
|||||||
To gracefully exit the application, press `ctrl-c`.
|
To gracefully exit the application, press `ctrl-c`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.executable-jar]]
|
[[getting-started.first-application.executable-jar]]
|
||||||
=== Creating an Executable Jar
|
=== Creating an Executable Jar
|
||||||
We finish our example by creating a completely self-contained executable jar file that we could run in production.
|
We finish our example by creating a completely self-contained executable jar file that we could run in production.
|
||||||
@ -382,9 +394,10 @@ It can also be problematic if the same filename is used (but with different cont
|
|||||||
Spring Boot takes a <<executable-jar#appendix.executable-jar, different approach>> and lets you actually nest jars directly.
|
Spring Boot takes a <<executable-jar#appendix.executable-jar, different approach>> and lets you actually nest jars directly.
|
||||||
****
|
****
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.executable-jar.maven]]
|
[[getting-started.first-application.executable-jar.maven]]
|
||||||
==== Maven
|
==== Maven
|
||||||
|
|
||||||
To create an executable jar, we need to add the `spring-boot-maven-plugin` to our `pom.xml`.
|
To create an executable jar, we need to add the `spring-boot-maven-plugin` to our `pom.xml`.
|
||||||
To do so, insert the following lines just below the `dependencies` section:
|
To do so, insert the following lines just below the `dependencies` section:
|
||||||
|
|
||||||
@ -458,9 +471,10 @@ To run that application, use the `java -jar` command, as follows:
|
|||||||
|
|
||||||
As before, to exit the application, press `ctrl-c`.
|
As before, to exit the application, press `ctrl-c`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[getting-started.first-application.executable-jar.gradle]]
|
[[getting-started.first-application.executable-jar.gradle]]
|
||||||
==== Gradle
|
==== Gradle
|
||||||
|
|
||||||
To create an executable jar, we need to run `gradle bootJar` from the command line, as follows:
|
To create an executable jar, we need to run `gradle bootJar` from the command line, as follows:
|
||||||
|
|
||||||
[source,shell,indent=0,subs="verbatim,attributes"]
|
[source,shell,indent=0,subs="verbatim,attributes"]
|
||||||
|
@ -28,6 +28,7 @@ import org.gradle.api.Plugin;
|
|||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.artifacts.Configuration;
|
import org.gradle.api.artifacts.Configuration;
|
||||||
import org.gradle.api.file.FileCollection;
|
import org.gradle.api.file.FileCollection;
|
||||||
|
import org.gradle.api.java.archives.Manifest;
|
||||||
import org.gradle.api.plugins.ExtensionAware;
|
import org.gradle.api.plugins.ExtensionAware;
|
||||||
import org.gradle.api.plugins.JavaPlugin;
|
import org.gradle.api.plugins.JavaPlugin;
|
||||||
import org.gradle.api.plugins.JavaPluginExtension;
|
import org.gradle.api.plugins.JavaPluginExtension;
|
||||||
@ -122,8 +123,15 @@ class NativeImagePluginAction implements PluginApplicationAction {
|
|||||||
private void configureJarManifestNativeAttribute(Project project) {
|
private void configureJarManifestNativeAttribute(Project project) {
|
||||||
project.getTasks()
|
project.getTasks()
|
||||||
.named(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class)
|
.named(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class)
|
||||||
.configure((bootJar) -> bootJar
|
.configure(this::addNativeProcessedAttribute);
|
||||||
.manifest(((manifest) -> manifest.getAttributes().put("Spring-Boot-Native-Processed", true))));
|
}
|
||||||
|
|
||||||
|
private void addNativeProcessedAttribute(BootJar bootJar) {
|
||||||
|
bootJar.manifest(this::addNativeProcessedAttribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addNativeProcessedAttribute(Manifest manifest) {
|
||||||
|
manifest.getAttributes().put("Spring-Boot-Native-Processed", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user