Skip to content

Commit 96a7ff3

Browse files
committed
Part III.Using Spring boot - 15.Configuration Classes
1 parent b3a231f commit 96a7ff3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 15. Configuration Class
2+
3+
# 15. 配置类
4+
5+
Spring Boot favors Java-based configuration. Although it is possible to use SpringApplication with XML sources, we generally recommend that your primary source be a single `@Configuration` class. Usually the class that defindes the main method is a good candidate as the primary `@Configuration`.
6+
7+
Spring Boot支持基于Java的配置。虽然可以将SpringApplication与XML源一起使用,我们通常建议你的主要源是一个`@Configuration`类。通常,这类中是定义了入口函数是主要的`@Configuration`比较好的地方。
8+
9+
##### Tip
10+
11+
##### 小提示
12+
13+
> Many Spring configuration examples have been published on the internet that use XML configuration. If possible, always try to use the equivalent Java-based configuration. Searching for `Enable*` annotations can be a good starting point.
14+
15+
> 许多使用XML配置的Spring配置示例被发布到Internet上。如果可能,请始终尝试使用基于Java等效的配置。搜索有关`Enable*`注解是一个很好的起点。
16+
17+
### Importing Additional Configuration Classes
18+
19+
### 导入附加配置类
20+
21+
You need not put all your `@Configuration` into a single class. The `@Import` annotation can be used to import additional configuration classes. Alternatively, you can use `@ComponentScan` to automatically pick up all Spring components, including `@Configuration` classes.
22+
23+
你不需要将所有的`@Configuration`都放在一个类中。使用`@Import`注解可以用来导入附加配置类。另外,你可以使用`@ComponentScan`来自动获取所有Spring组件,包含`@Configuration`类。
24+
25+
### Imporing XML Configuration
26+
27+
### 导入XML配置
28+
29+
If you absolutely must use XML based configuration, we recommend that you still start with a `@Configuration` class. You can then use an `@ImportResource` annotation to load XML configuration files.
30+
31+
如果你必须需要使用基于XML的配置,我们建议你仍从`@Configuration`类开始。你可以使用`@ImportResource`注解来加载XML配置文件。

0 commit comments

Comments
 (0)