File tree Expand file tree Collapse file tree 6 files changed +70
-0
lines changed
Expand file tree Collapse file tree 6 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ package io .nononi .week5 .annotation ;
2+
3+ import org .springframework .context .annotation .ComponentScan ;
4+ import org .springframework .context .annotation .Configuration ;
5+
6+ /**
7+ * 利用注解注入
8+ */
9+ @ Configuration
10+ @ ComponentScan
11+ public class AnnotationConfig {
12+ }
Original file line number Diff line number Diff line change 1+ package io .nononi .week5 .annotation ;
2+
3+ import org .springframework .stereotype .Component ;
4+
5+ /**
6+ * 自动注入样例
7+ */
8+ @ Component
9+ public class AnnotationExample {
10+ public void printMsg (){
11+ System .out .println ("通过注解自动注入" );
12+ }
13+ }
Original file line number Diff line number Diff line change 1+ package io .nononi .week5 .javacode ;
2+
3+ import org .springframework .context .annotation .Bean ;
4+ import org .springframework .context .annotation .Configuration ;
5+
6+ /**
7+ * java配置类
8+ */
9+ @ Configuration
10+ public class JavaCodeConfig {
11+
12+ @ Bean
13+ public JavaCodeExample javaCodeExample (){
14+ return new JavaCodeExample ();
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ package io .nononi .week5 .javacode ;
2+
3+ import org .springframework .stereotype .Component ;
4+
5+ /**
6+ * 待装配的Bean
7+ */
8+ @ Component
9+ public class JavaCodeExample {
10+ public void printMsg (){
11+ System .out .println ("Java配置类注入" );
12+ }
13+ }
Original file line number Diff line number Diff line change 1+ package io .nononi .week5 .xml ;
2+
3+ public class XmlExample {
4+ public void printMsg (){
5+ System .out .println ("XML装配Bean" );
6+ }
7+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <beans xmlns =" http://www.springframework.org/schema/beans"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://www.springframework.org/schema/beans
5+ http://www.springframework.org/schema/beans/spring-beans.xsd" >
6+
7+ <bean id =" xmlExample" class =" io.nononi.week5.xml.XmlExample" />
8+
9+ </beans >
You can’t perform that action at this time.
0 commit comments