public class UserConfiguration {
private int id;
private String name;
private String city;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
public class UserClient {
private UserConfiguration configuration;
public UserClient(UserConfiguration configuration) {
this.configuration = configuration;
}
public String getCity() {
return configuration.getCity();
}
}
<?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 id="userConfiguration" class="com.rhwayfun.springboot.starter.rest.UserConfiguration">
<property name="id" value="${user1.id}"/>
<property name="name" value="${user1.name}"/>
<property name="city" value="${user1.city}"/>
</bean>
<bean id="userClient" class="com.rhwayfun.springboot.starter.rest.UserClient" autowire="byName">
<constructor-arg ref="userConfiguration"/>
</bean>
</beans>
<?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 id="userConfiguration" class="com.rhwayfun.springboot.starter.rest.UserConfiguration">
<property name="id" value="${user2.id}"/>
<property name="name" value="${user2.name}"/>
<property name="city" value="${user2.city}"/>
</bean>
<bean id="userClient2" class="com.rhwayfun.springboot.starter.rest.UserClient">
<constructor-arg ref="userConfiguration"/>
</bean>
</beans>
user1.id=1 user1.name=bean1 user1.city=Hangzhou user2.id=2 user2.name=bean2 user2.city=Shanghai
@SpringBootApplication
public class Application{
@Autowired
UserClient userClient2;
@PostConstruct
public void init() {
String city = userClient2.getCity();
System.out.println(city);
}
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(Application.class, args);
Thread.sleep(Long.MAX_VALUE);
}
}
Overriding bean definition for bean 'userConfiguration' with a different definition: replacing [Generic bean: class [com.rhwayfun.springboot.starter.rest.UserConfiguration]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [/Users/chubin/IdeaProjects/spring-boot-learning-examples/ spring-boot-starter-rest/target/classes/beans.xml]] with [Generic bean: class [com.rhwayfun.springboot.starter.rest.UserConfiguration]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [/Users/chubin/IdeaProjects/spring-boot-learning-examples /spring-boot-starter-rest/target/classes/beans2.xml]]
/** * Useful constant for the highest precedence value. * @see java.lang.Integer#MIN_VALUE */ int HIGHEST_PRECEDENCE = Integer.MIN_VALUE; /** * Useful constant for the lowest precedence value. * @see java.lang.Integer#MAX_VALUE */ int LOWEST_PRECEDENCE = Integer.MAX_VALUE;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有