天天看點

Atitit.ioc 動态配置檔案guice 設計原理

Atitit.ioc 動态配置檔案guice 設計原理

1. Bat啟動時注入配置檔案1

2. ioc調用1

3. Ioc 分發器 配合 apche  MethodUtils.invokeStaticMethod2

1. Bat啟動時注入配置檔案

SET JAVA_HOME=C:\Program Files\Java\jdk1.8.0_71

set  RESIN-HOME=c:\resin-4.0.22

set classpath=%classpath%;%RESIN-HOME%\lib\jasper.jar;%RESIN-HOME%\lib\javaee-16.jar;%RESIN-HOME%\lib\resin.jar

rem 3,配置classpath %RESIN-HOME%\lib\resin.jar (如果是win7的話沒必要設定)

rem  否則報異常:com.caucho.loader.SystemClassLoader

rem %RESIN-HOME%\resin.exe console  -resin-home %RESIN-HOME% --debug-port 8000

 "%JAVA_HOME%\bin\java" -Dresin.server=1 -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djava.system.class.loader=com.caucho.loader.SystemClassLoader -Djava.endorsed.dirs="%java_home%\jre\lib\endorsed;E:\resin-4.0.22\endorsed" -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/%RESIN-HOME% -Xss1m -Xmx556m -Xrs -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 com.caucho.server.resin.Resin --root-directory /%RESIN-HOME% -conf %RESIN-HOME%\conf\resin.xml   -resin-home /%RESIN-HOME% -root-directory /%RESIN-HOME% console -debug-port 8000 -Dapptype="jobus"

作者:: 綽号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿爾 拉帕努伊 ) 漢字名:艾龍, 

2. ioc調用

this.dbx=com.attilax.ioc.IocXq214.getBean(DBX.class);

3. Ioc 分發器 配合 apche  MethodUtils.invokeStaticMethod

/**

 * @author attilax 老哇的爪子

@since  o92 j_48_u$

 */

package com.attilax.ioc;

import com.attilax.core;

import com.attilax.db.DBX;

import com.attilax.db.DbxMybatis;

import com.attilax.persistence.HbxX;

import com.attilax.persistence.PX;

import com.focustar.ServiceLoctor4vod;

import com.focustar.downtask.GvDownloadTaskSvs;

import com.google.inject.Binder;

import com.google.inject.Guice;

import com.google.inject.Injector;

import com.google.inject.Module;

import com.google.inject.name.Names;

import static  com.attilax.core.*;

import java.util.*;

import java.net.*;

import java.io.*;

import org.apache.commons.lang3.reflect.MethodUtils;

//import org.directwebremoting.extend.AbstractCreator;

//import org.directwebremoting.extend.Creator;

 * @author  attilax 老哇的爪子

 *@since  o92 j_48_u$

public class IocXq214   {

//publicstatic Injector ati;

public static void main(String[] args) {

System.setProperty("apptype","jobus");

System.out.println(getBean(DBX.class));

}

@author attilax 老哇的爪子

@since  o92 j_48_40   

 * @param class1

 * @return

public  static  <t> t getBean(Class<t> class1) {

 String apptype=System.getProperty("apptype");

 String clsName="aaaCfg.IocX4@app@".replace("@app@", apptype);

Object o= com.attilax.reflect.MethodUtils.invokeStaticMethod(clsName, "getBean", (Object)class1);

// attilax 老哇的爪子  j_48_40   o92 

return    (t) o;

//  attilax 老哇的爪子 j_48_u   o92   

/* (non-Javadoc)

 * @see org.directwebremoting.extend.Creator#getType()

 *@since  o93 l_d_c$

@since  o02 4_f_56   

 * @param string

public     <t> t getBean(String className) {

// attilax 老哇的爪子  4_f_56   o02 

try {

Class c=Class.forName(className);

return (t) getBean(c);

} catch (ClassNotFoundException e) {

//  attilax 老哇的爪子 4_h_t   o02   

e.printStackTrace();

throw new RuntimeException(e);

//return null;

//  attilax 老哇的爪子