Use convention based code imports
Closes gh-29647
This commit is contained in:
@@ -25,10 +25,7 @@ Doing so enables debug logs for a selection of core loggers and logs a condition
|
||||
=== Disabling Specific Auto-configuration Classes
|
||||
If you find that specific auto-configuration classes that you do not want are being applied, you can use the exclude attribute of `@SpringBootApplication` to disable them, as shown in the following example:
|
||||
|
||||
[source,java,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::{docs-java}/using/autoconfiguration/disablingspecific/MyApplication.java[]
|
||||
----
|
||||
include::code:MyApplication[]
|
||||
|
||||
If the class is not on the classpath, you can use the `excludeName` attribute of the annotation and specify the fully qualified name instead.
|
||||
If you prefer to use `@EnableAutoConfiguration` rather than `@SpringBootApplication`, `exclude` and `excludeName` are also available.
|
||||
|
||||
@@ -178,10 +178,7 @@ In most cases, you can set this property in your `application.properties` (doing
|
||||
|
||||
If you need to _completely_ disable restart support (for example, because it does not work with a specific library), you need to set the configprop:spring.devtools.restart.enabled[] `System` property to `false` before calling `SpringApplication.run(...)`, as shown in the following example:
|
||||
|
||||
[source,java,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::{docs-java}/using/devtools/restart/disable/MyApplication.java[]
|
||||
----
|
||||
include::code:MyApplication[]
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,16 +8,10 @@ All of your application components (`@Component`, `@Service`, `@Repository`, `@C
|
||||
|
||||
The following example shows a `@Service` Bean that uses constructor injection to obtain a required `RiskAssessor` bean:
|
||||
|
||||
[source,java,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::{docs-java}/using/springbeansanddependencyinjection/singleconstructor/MyAccountService.java[]
|
||||
----
|
||||
include::code:singleconstructor/MyAccountService[]
|
||||
|
||||
If a bean has more than one constructor, you will need to mark the one you want Spring to use with `@Autowired`:
|
||||
|
||||
[source,java,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::{docs-java}/using/springbeansanddependencyinjection/multipleconstructors/MyAccountService.java[]
|
||||
----
|
||||
include::code:multipleconstructors/MyAccountService[]
|
||||
|
||||
TIP: Notice how using constructor injection lets the `riskAssessor` field be marked as `final`, indicating that it cannot be subsequently changed.
|
||||
|
||||
@@ -48,7 +48,4 @@ The following listing shows a typical layout:
|
||||
|
||||
The `MyApplication.java` file would declare the `main` method, along with the basic `@SpringBootApplication`, as follows:
|
||||
|
||||
[source,java,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::{docs-java}/using/structuringyourcode/locatingthemainclass/MyApplication.java[]
|
||||
----
|
||||
include::code:MyApplication[]
|
||||
|
||||
@@ -8,10 +8,7 @@ A single `@SpringBootApplication` annotation can be used to enable those three f
|
||||
* `@SpringBootConfiguration`: enable registration of extra beans in the context or the import of additional configuration classes.
|
||||
An alternative to Spring's standard `@Configuration` that aids <<features#features.testing.spring-boot-applications.detecting-configuration,configuration detection>> in your integration tests.
|
||||
|
||||
[source,java,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::{docs-java}/using/usingthespringbootapplicationannotation/springapplication/MyApplication.java[]
|
||||
----
|
||||
include::code:springapplication/MyApplication[]
|
||||
|
||||
NOTE: `@SpringBootApplication` also provides aliases to customize the attributes of `@EnableAutoConfiguration` and `@ComponentScan`.
|
||||
|
||||
@@ -20,10 +17,7 @@ NOTE: `@SpringBootApplication` also provides aliases to customize the attributes
|
||||
None of these features are mandatory and you may choose to replace this single annotation by any of the features that it enables.
|
||||
For instance, you may not want to use component scan or configuration properties scan in your application:
|
||||
|
||||
[source,java,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::{docs-java}/using/usingthespringbootapplicationannotation/individualannotations/MyApplication.java[]
|
||||
----
|
||||
include::code:individualannotations/MyApplication[]
|
||||
|
||||
In this example, `MyApplication` is just like any other Spring Boot application except that `@Component`-annotated classes and `@ConfigurationProperties`-annotated classes are not detected automatically and the user-defined beans are imported explicitly (see `@Import`).
|
||||
====
|
||||
|
||||
Reference in New Issue
Block a user