标签:schema classpath messages 内容 new oid getconf factory col
Bean管理注解实现
<context:component-scan base-package="com.jing.spring.annotation"></context:component-scan>
private BeanTest beanTest; @Autowired private void setBeanTest ( BeanTest beanTest){ this.beanTest =beanTest; }
class BeanAnnotation{ private BeanTest beanTest; @Autowired public BeanTest ( BeanTest beanTest){ this.beanTest =beanTest; } }
class BeanAnnotation{ @Autowired private BeanTest beanTest; public BeanTest ( BeanTest beanTest){ this.beanTest =beanTest; } }
class BeanAnnotation{ @Autowired(required=false) private BeanTest beanTest; public BeanTest ( BeanTest beanTest){ this.beanTest =beanTest; } }
public class TestAutowired{ @Autowired private ApplicationContext application; public TestAutowired{ application.getBean(""); } }
public class TestAutowired{ //AutowiredBeanI为接口,实现这个接口的类都将注入到list中 @Autowired private List<AutowiredBeanI> list; }
public class TestAutowired{ //AutowiredBeanI为接口,实现这个接口的类都将注入到map中 @Autowired private Map<String,AutowiredBeanI> map; }
@Component(value = "qualifierEntry") public class QualifierEntry { @Autowired @Qualifier(value = "qualifierOne") private List<TestQualifierI> qualifierIS; public void print(){ for (TestQualifierI qualifier:qualifierIS) { qualifier.say(); } } }
package com.jing.spring.annotation; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;
@Configuration public class Configure { @Bean(value = {"configure2","configure1"},initMethod = "init",destroyMethod = "destroy") public BeanConfigureI beanCon(){ return new BeanConfigureImpl(); } }
<!-- spring-config.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd" >
<context:property-placeholder location="classpath:/config.properties"></context:property-placeholder>
</beans>
#config.properties
url:127.0.0.1
name:jingguoliang
package com.jing.spring.annotation; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; @Configuration @ImportResource(locations = {"classpath:spring-config.xml"}) public class Configure { @Value(value = "url") private String url; @Value(value = "name") private String name; @Bean(value = {"configResource"}) public ValueAndReImportResource getConfigResource(){ ValueAndReImportResource valueAndReImportResource = new ValueAndReImportResource(url,name); return valueAndReImportResource; } }
标签:schema classpath messages 内容 new oid getconf factory col
原文地址:https://www.cnblogs.com/jixue/p/9990961.html