siye@r480:~/svlution/workspace/springcore4322$ tree src/
src/
├── main
│ ├── java
│ │ ├── log4j.properties
│ │ └── ocn
│ │ └── site
│ │ └── springioc
│ │ └── domain
│ │ └── User.java
│ └── resources
└── test
├── java
│ └── ocn
│ └── site
│ └── springioc
│ └── domain
│ └── Runtest.java
└── resources
└── config
└── application.xml
15 directories, 4 files
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.22.RELEASE</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.22.RELEASE</version>
<scope>test</scope>
</dependency>
package ocn.site.springioc.domain;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private List<Integer> list;
private Set<Integer> set;
private Map<Integer, String> map;
private Integer[] array;
private Properties props;
public List<Integer> getList() {
return list;
}
public void setList(List<Integer> list) {
this.list = list;
}
public Set<Integer> getSet() {
return set;
}
public void setSet(Set<Integer> set) {
this.set = set;
}
public Map<Integer, String> getMap() {
return map;
}
public void setMap(Map<Integer, String> map) {
this.map = map;
}
public Integer[] getArray() {
return array;
}
public void setArray(Integer[] array) {
this.array = array;
}
public Properties getProps() {
return props;
}
public void setProps(Properties props) {
this.props = props;
}
@Override
public String toString() {
return "User [list=" + list + ", set=" + set + ", map=" + map + ", array=" + Arrays.toString(array) + ", props="
+ props + "]";
}
public User(List<Integer> list, Set<Integer> set, Map<Integer, String> map, Integer[] array, Properties props) {
super();
this.list = list;
this.set = set;
this.map = map;
this.array = array;
this.props = props;
}
public User() {
super();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="ocn.site.springioc.domain.User">
<property name="list">
<list value-type="java.lang.Integer" merge="default">
<value>0</value>
<value>0</value>
<value>0</value>
</list>
</property>
<property name="set">
<set value-type="java.lang.Integer" merge="default">
<value>0</value>
<value>1</value>
<value>2</value>
</set>
</property>
<property name="map">
<map key-type="java.lang.Integer" value-type="java.lang.String" merge="default">
<entry key="0" value="jack"></entry>
<entry key="1" value="rose"></entry>
<entry key="2" value="hack"></entry>
</map>
</property>
<property name="array">
<array value-type="java.lang.Integer" merge="default">
<value>3</value>
<value>3</value>
<value>3</value>
</array>
</property>
<property name="props">
<props value-type="java.lang.String" merge="default">
<prop key="0">aaa</prop>
<prop key="1">bbb</prop>
<prop key="2">ccc</prop>
</props>
</property>
</bean>
</beans>
package ocn.site.springioc.domain;
import java.util.Arrays;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:config/application.xml")
public class Runtest {
private final Logger logger = Logger.getLogger(this.getClass());
private @Autowired User user;
@Test
public void run() throws Exception {
logger.info(user.getList());
logger.info(user.getSet());
logger.info(user.getMap());
logger.info(user.getProps());
logger.info(Arrays.toString(user.getArray()));
}
}
19-09-08 15:43:36 org.springframework.test.context.support.DefaultTestContextBootstrapper =====>>> Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
19-09-08 15:43:36 org.springframework.test.context.support.DefaultTestContextBootstrapper =====>>> Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@4e04a765, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@783e6358, org.springframework.test.context.support.DirtiesContextTestExecutionListener@17550481]
19-09-08 15:43:36 org.springframework.beans.factory.xml.XmlBeanDefinitionReader =====>>> Loading XML bean definitions from class path resource [config/application.xml]
19-09-08 15:43:37 org.springframework.context.support.GenericApplicationContext =====>>> Refreshing org.springframework.context.support.GenericApplicationContext@2ef5e5e3: startup date [Sun Sep 08 15:43:37 CST 2019]; root of context hierarchy
19-09-08 15:43:37 ocn.site.springioc.domain.Runtest =====>>> [0, 0, 0]
19-09-08 15:43:37 ocn.site.springioc.domain.Runtest =====>>> [0, 1, 2]
19-09-08 15:43:37 ocn.site.springioc.domain.Runtest =====>>> {0=jack, 1=rose, 2=hack}
19-09-08 15:43:37 ocn.site.springioc.domain.Runtest =====>>> {2=ccc, 1=bbb, 0=aaa}
19-09-08 15:43:37 ocn.site.springioc.domain.Runtest =====>>> [3, 3, 3]
19-09-08 15:43:37 org.springframework.context.support.GenericApplicationContext =====>>> Closing org.springframework.context.support.GenericApplicationContext@2ef5e5e3: startup date [Sun Sep 08 15:43:37 CST 2019]; root of context hierarchy