目录
基础
demo
基础
demo
content-inject
<?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">
<!--实时查找-->
<import resource="content.xml" />
<bean id="userRepos" class="com.test.repos.UserRepos" autowire="byType" />
<alias name="user" alias="user2" />
</beans>
InjectDemo
package com.test;
import com.test.anonation.VIP;
import com.test.pojo.User;
import com.test.repos.UserRepos;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.Environment;
import java.util.Map;
public class InjectDemo {
public static void main(String[] args) {
BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/content-inject.xml") ;
User user = beanFactory.getBean("user",User.class);
User user2 = beanFactory.getBean("user2",User.class);
System.out.println(user == user2);
}
}