日期:2014-05-19  浏览次数:20746 次

不使用框架,如何实现依赖注入
如题!

  求教,谁给说说!

  或者发个demo也行,先谢谢了.

------解决方案--------------------
那就使用自定义框架吧
http://download.csdn.net/detail/s478853630/4263505
试试看
------解决方案--------------------
http://syue.com/Software/JAVA/15753.html
http://only1.iteye.com/blog/733550
百度一下,很多的。
------解决方案--------------------
探讨

引用:

那就使用自定义框架吧
http://download.csdn.net/detail/s478853630/4263505
试试看


大哥,下载分好高啊。。。我分不够,555

------解决方案--------------------
你下载了别人的资源都还没评论的吧
伸出你那温柔的双手评论一下吧,就有分了。
我的邮箱只有2M的空间,网易很小气啊,没办法咯
------解决方案--------------------
去看看spring注解的源代码,看懂了,就会写了。spring底层也是通过反射实现ioc的。
------解决方案--------------------
探讨

去看看spring注解的源代码,看懂了,就会写了。spring底层也是通过反射实现ioc的。

------解决方案--------------------
片段代码:


package com.org.mvc2.web;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Timer;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.org.mvc2.entity.JdbcConfig;
import com.org.mvc2.entity.ModelBean;
import com.org.mvc2.entity.Settled;
import com.org.mvc2.exciption.MvcException;
import com.org.mvc2.model.CacheIdTimer;
import com.org.mvc2.util.ReflectUtil;

/**
 * 自定义框架的核心ModelBean和Control
 * @version 2.0
 * */
public class Mvc2BeanControlServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

/**
* 初始化
* @throws ServletException
* */
public void init() throws ServletException {
String config = getInitParameter(Settled.BEAN_CONTROL_CONFIG);
if (null != config && !"".equals(config)) {
String[] configPath = config.split(",");
for (int i = 0; i < configPath.length; i++) {
if (configPath[i].indexOf("classes") != -1) {
configPath[i] = configPath[i].substring(configPath[i].lastIndexOf("classes") + 8);
}
}
loadConfig(configPath, ReflectUtil.getClasspath());
Long interval = 1000l * 60l * 4l;
new Timer().schedule(new CacheIdTimer(), interval, interval);// 四分钟执行一次
}
}

/**
* 加载配置文件
* @param configPath 配置文件路径,多个文件用数组
* @param basePath class的根目录
* */ 
@SuppressWarnings("unchecked")
public void loadConfig(String[] configPath, String basePath) {
try {
List<String> packageList = new ArrayList<String>();
if (null != configPath && configPath.length > 0) {
for (int i = 0; i < configPath.length; i++) {
File file = new File(basePath + configPath[i]);
if (!file.exists()) {
throw new MvcException("找不到[" + configPath[i] + "]这个配置文件!");
}
Element root = new SAXReader().read(file).getRootElement();// 根节点
Iterator iterator = root.elements().iterator();
while (iterator.hasNext()) {<