1.首先在工程中引入bboss ioc
maven坐标:
com.bbossgroups bboss-core 5.0.3.5
gradle坐标:
compile group: 'com.bbossgroups', name: 'bboss-core', version: '5.0.3.5'
2.编写组件实现
org.gradle.IOCExample
package org.gradle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class IOCExample { private static final Logger logger = LoggerFactory.getLogger(IOCExample.class); private String name ; private String sex; private String homepage; public void init(){ logger.debug("init bean............."); } public String exampMethod(){ return new StringBuilder().append("name = ").append(name).append(",") .append("sex = ").append(sex).append(",") .append("homepage = ").append(homepage).toString(); } }
3.定义外部属性配置-config.properties
name=杰克 homepage=http://www.bbossgroups.com
4.配置bboss ioc
编写bboss ioc配置文件:exampile.xml,放到工程resources目录
5.测试用例
package org.gradle; import org.frameworkset.spi.BaseApplicationContext; import org.frameworkset.spi.DefaultApplicationContext; import org.junit.Test; /** * Created by 1 on 2017/6/25. */ public class TestInvoke { @Test public void test(){ //初始化ioc容器 BaseApplicationContext context = DefaultApplicationContext.getApplicationContext("example.xml"); //获取组件实例 IOCExample example = context.getTBeanObject("examplebean",IOCExample.class); //调用组件方法 String message = example.exampMethod(); System.out.println("message:"+message); } }
6.构建和运行
在构建和运行之前先安装并配置好gradle环境,gradle的安装和配置参考文档:
http://yin-bp.iteye.com/blog/2313145
下载示例: 下载
解压下载的文件,后切换到cmd,在testioc目录下执行命令:
gradle releaseVersion
然后切换到目录build/dist下面,运行指令:start.bat就可以看效果了: