Skip to content

Commit d6469d3

Browse files
committed
updated
updated
1 parent dbd83a3 commit d6469d3

File tree

9 files changed

+118
-95
lines changed

9 files changed

+118
-95
lines changed

spring-core-config/.classpath

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
<classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
66
<classpathentry kind="output" path="target/classes"/>
77
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
8-
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/3.2.3.RELEASE/spring-core-3.2.3.RELEASE.jar"/>
8+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/3.1.0.RELEASE/spring-core-3.1.0.RELEASE.jar"/>
9+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-asm/3.1.0.RELEASE/spring-asm-3.1.0.RELEASE.jar"/>
910
<classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
10-
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/3.2.3.RELEASE/spring-beans-3.2.3.RELEASE.jar"/>
11-
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/3.2.3.RELEASE/spring-context-3.2.3.RELEASE.jar"/>
12-
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-aop/3.2.3.RELEASE/spring-aop-3.2.3.RELEASE.jar"/>
11+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/3.1.0.RELEASE/spring-beans-3.1.0.RELEASE.jar"/>
12+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/3.1.0.RELEASE/spring-context-3.1.0.RELEASE.jar"/>
13+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-aop/3.1.0.RELEASE/spring-aop-3.1.0.RELEASE.jar"/>
1314
<classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar" sourcepath="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar"/>
14-
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-expression/3.2.3.RELEASE/spring-expression-3.2.3.RELEASE.jar"/>
15+
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-expression/3.1.0.RELEASE/spring-expression-3.1.0.RELEASE.jar"/>
16+
<classpathentry kind="var" path="M2_REPO/cglib/cglib/2.2.2/cglib-2.2.2.jar"/>
17+
<classpathentry kind="var" path="M2_REPO/asm/asm/3.3.1/asm-3.3.1.jar"/>
1518
</classpath>

spring-core-config/pom.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,29 @@
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<org.springframework.version>3.1.0.RELEASE</org.springframework.version>
1516
</properties>
1617

1718
<dependencies>
1819
<dependency>
1920
<groupId>org.springframework</groupId>
2021
<artifactId>spring-core</artifactId>
21-
<version>3.2.3.RELEASE</version>
22+
<version>${org.springframework.version}</version>
2223
</dependency>
2324
<dependency>
2425
<groupId>org.springframework</groupId>
2526
<artifactId>spring-beans</artifactId>
26-
<version>3.2.3.RELEASE</version>
27+
<version>${org.springframework.version}</version>
2728
</dependency>
2829
<dependency>
2930
<groupId>org.springframework</groupId>
3031
<artifactId>spring-context</artifactId>
31-
<version>3.2.3.RELEASE</version>
32-
</dependency>
32+
<version>${org.springframework.version}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>cglib</groupId>
36+
<artifactId>cglib</artifactId>
37+
<version>2.2.2</version>
38+
</dependency>
3339
</dependencies>
3440
</project>

spring-core-config/src/main/java/com/hmkcode/App.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
55
import org.springframework.context.support.ClassPathXmlApplicationContext;
66

7+
import com.hmkcode.spring.beans.AnotherBean;
78
import com.hmkcode.spring.beans.MyBean;
8-
import com.hmkcode.spring.beans.MyBeanAnnotated;
99
import com.hmkcode.spring.config.JavaConfig;
1010

1111

@@ -15,20 +15,26 @@ public static void main( String[] args )
1515
{
1616

1717

18-
ApplicationContext ctxXML = new ClassPathXmlApplicationContext("config/XMLConfig.xml");
19-
MyBean myBean = (MyBean) ctxXML.getBean("myBean");
20-
21-
System.out.println( myBean);
18+
ApplicationContext ctxXML = new ClassPathXmlApplicationContext("config/XMLConfig.xml");
19+
AnotherBean anotherBean = (AnotherBean) ctxXML.getBean("anotherBean");
20+
21+
System.out.println( anotherBean);
22+
23+
//---------------------------------------
24+
2225

2326
ApplicationContext ctxAnnotation = new ClassPathXmlApplicationContext("config/XMLConfig-Annotation.xml");
24-
myBean = (MyBean) ctxAnnotation.getBean("myBean2");
25-
26-
System.out.println( myBean);
27+
anotherBean = (AnotherBean) ctxAnnotation.getBean("anotherBean");
28+
29+
System.out.println( anotherBean);
2730

28-
ApplicationContext ctxJavaConfig = new AnnotationConfigApplicationContext(JavaConfig.class);
29-
myBean = (MyBean) ctxJavaConfig.getBean("myBean3");
31+
//---------------------------------------
3032

31-
System.out.println( myBean);
33+
34+
ApplicationContext ctxJavaConfig = new AnnotationConfigApplicationContext(JavaConfig.class);
35+
anotherBean = (AnotherBean) ctxJavaConfig.getBean("anotherBean2");
36+
37+
System.out.println( anotherBean);
3238

3339
}
3440
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.hmkcode.spring.beans;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.beans.factory.annotation.Qualifier;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component(value="anotherBean")
8+
public class AnotherBean {
9+
10+
private MyBean myBean;
11+
12+
public MyBean getMyBean() {
13+
return myBean;
14+
}
15+
16+
@Autowired
17+
@Qualifier("myBean")
18+
public void setMyBean(MyBean myBean) {
19+
this.myBean = myBean;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return "AnotherBean [myBean=" + myBean + "]";
25+
}
26+
27+
28+
}
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
package com.hmkcode.spring.beans;
2-
3-
import org.springframework.beans.factory.annotation.Required;
2+
43
import org.springframework.beans.factory.annotation.Value;
54
import org.springframework.stereotype.Component;
6-
7-
@Component(value="myBean2")
5+
6+
@Component(value="myBean")
87
public class MyBean {
9-
10-
private String name;
11-
12-
public String getName() {
13-
return name;
14-
}
15-
16-
@Value(value="BeanName")
17-
public void setName(String name) {
18-
this.name = name;
19-
}
20-
21-
@Override
22-
public String toString() {
23-
return "MyBean [name=" + name + "]";
24-
}
25-
26-
}
8+
9+
private String name;
10+
11+
public String getName() {
12+
return name;
13+
}
14+
15+
@Value(value="AnnotationBean")
16+
public void setName(String name) {
17+
this.name = name;
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return "MyBean [name=" + name + "]";
23+
}
24+
25+
}

spring-core-config/src/main/java/com/hmkcode/spring/beans/MyBeanAnnotated.java

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package com.hmkcode.spring.config;
2-
2+
33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;
5-
5+
import com.hmkcode.spring.beans.AnotherBean;
66
import com.hmkcode.spring.beans.MyBean;
7-
7+
88
@Configuration
99
public class JavaConfig {
10-
11-
@Bean(name = "myBean3")
12-
public MyBean myBean(){
13-
MyBean myBean = new MyBean();
14-
myBean.setName("myBeanJavaConfig");
15-
return myBean;
16-
}
17-
}
10+
11+
@Bean
12+
public MyBean myBean(){
13+
return new MyBean();
14+
}
15+
16+
@Bean(name = "anotherBean2")
17+
public AnotherBean anotherBean(){
18+
return new AnotherBean();
19+
}
20+
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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-
xmlns:context="http://www.springframework.org/schema/context"
5-
xsi:schemaLocation="http://www.springframework.org/schema/beans
6-
http://www.springframework.org/schema/beans/spring-beans.xsd
7-
http://www.springframework.org/schema/context
8-
http://www.springframework.org/schema/context/spring-context.xsd">
9-
10-
<context:component-scan base-package="com.hmkcode.spring.beans"/>
1+
<?xml version="1.0" encoding="UTF-8"?>
112

3+
<beans xmlns="http://www.springframework.org/schema/beans"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:context="http://www.springframework.org/schema/context"
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans
7+
http://www.springframework.org/schema/beans/spring-beans.xsd
8+
http://www.springframework.org/schema/context
9+
http://www.springframework.org/schema/context/spring-context.xsd">
10+
<context:component-scan base-package="com.hmkcode.spring.beans"/>
11+
<!-- The use of <context:component-scan> implicitly enables the functionality of <context:annotation-config> -->
1212
</beans>

spring-core-config/src/main/resources/config/XMLConfig.xml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://www.springframework.org/schema/beans
5-
http://www.springframework.org/schema/beans/spring-beans.xsd">
6-
7-
<bean id="myBean" class="com.hmkcode.spring.beans.MyBean">
8-
<property name="name" value="xmlBean" />
9-
</bean>
5+
6+
http://www.springframework.org/schema/beans/spring-beans.xsd">
7+
8+
<bean id="myBean" class="com.hmkcode.spring.beans.MyBean">
9+
<property name="name" value="xmlBean" />
10+
</bean>
11+
12+
<bean id="anotherBean" class="com.hmkcode.spring.beans.AnotherBean">
13+
<property name="myBean" ref="myBean" />
14+
</bean>
1015
</beans>

0 commit comments

Comments
 (0)