Skip to content

Commit c4d339b

Browse files
author
nononi
committed
第五周作业2
1 parent b55fd7c commit c4d339b

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.nononi.week5.xml;
2+
3+
public class XmlExample {
4+
public void printMsg(){
5+
System.out.println("XML装配Bean");
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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>

0 commit comments

Comments
 (0)