spring中xml转化成对应bean的几种方式

来源:互联网 发布:2017淘宝c店 编辑:程序博客网 时间:2024/05/29 16:51
1、bean文件配置成对应的.xml
     <inport />对应的xml配置文件
    调用就直接用@resource 对应的bean 就可用

2、bean文件配置成对应的.xml
     <inport />对应的xml配置文件

    @Autowired (装载)
    private ApplicationContext applicationContext;
    AuthMenu authMenu=(AuthMenu) applicationContext.getBean("authMenu");


3、 直接用 FileSystemXmlApplicationContext 去解析xml转化成对应的bean
 ApplicationContext factory=new FileSystemXmlApplicationContext("/src/main/resources/spring/spring-config-auth.xml");
 AuthMenu authMenu=(AuthMenu) factory.getBean("authMenu");
0 0
原创粉丝点击