Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
b099471d
Commit
b099471d
authored
Apr 10, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
b91e03b9
2d930fd6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
7 deletions
+20
-7
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+20
-7
No files found.
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
b099471d
...
...
@@ -5264,16 +5264,29 @@ potentially time consuming process of loading the context will only happen once.
[[boot-features-testing-spring-boot-applications-excluding-config]]
==== Excluding test configuration
If your application uses component scanning, for example if you use
`@SpringBootApplication` or `@ComponentScan`, you may find
components or configuration
s
`@SpringBootApplication` or `@ComponentScan`, you may find
top-level configuration classe
s
created only for specific tests accidentally get picked up everywhere.
To help prevent this, Spring Boot provides `@TestComponent` and `@TestConfiguration`
annotations that can be used on classes in `src/test/java` to indicate that they should
not be picked up by scanning.
As we <<boot-features-testing-spring-boot-applications-detecting-config,have seen above>>,
`@TestConfiguration` can be used on an inner class of a test to customize the primary
configuration. When placed on a top-level class, `@TestConfiguration` indicates that
classes in `src/test/java` should not be picked up by scanning. You can then import that
class explicitly where it is required:
NOTE: `@TestComponent` and `@TestConfiguration` are only needed on top level classes. If
you define `@Configuration` or `@Component` as inner-classes within a test (any class
that has `@Test` methods or `@RunWith`), they will be automatically filtered.
[source,java,indent=0]
----
@RunWith(SpringRunner.class)
@SpringBootTest
@Import(MyTestsConfiguration.class)
public class MyTests {
@Test
public void exampleTest() {
...
}
}
----
NOTE: If you directly use `@ComponentScan` (i.e. not via `@SpringBootApplication`) you
will need to register the `TypeExcludeFilter` with it. See
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment