01.bean
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Mobile implements Serializable {
private String name;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable {
private String name;
private Integer age;
}
02.config
@Configuration
public class SpringConf {
@Bean
public User user02(){
return new User("za",1);
}
}
或
<?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-2.5.xsd">
<bean id="user01" class="cn.ccut.beans.User">
<property name="name" value="user01"></property>
<property name="age" value="18"></property>
</bean>
<bean id="mobile01" class="cn.ccut.beans.Mobile">
<property name="name" value="xiaomi"></property>
</bean>
</beans>
03.测试
ConfigurableApplicationContext run = SpringApplication.run(Demo81MongodbTestApplication.class, args);
String[] beanDefinitionNames = run.getBeanDefinitionNames();
for (int i = 0; i < beanDefinitionNames.length; i++) {
System.err.println(beanDefinitionNames[i]);
}