论坛首页 入门技术论坛

Spring 2.0 的 IOC 问题!??

浏览 1856 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-05-17  
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="mappingResources">
			<list>
				<value>pojo/Euser.hbm.xml</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.Oracle9Dialect
				</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
	</bean>

	<bean id="baseDao" class="common.dao.BaseDaoImp">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	
	<bean id="queryDao" class="common.dao.QueryDaoImp">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	
	<bean id="userDAO" class="common.dao.UserDAO">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	
	
	<bean id="pageQueryDao" class="common.dao.PageQueryDaoImp">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<bean name="baseService" class="common.BaseService">
		<property name="baseDao" ref="baseDao" />
		<property name="pageQueryDao" ref="pageQueryDao" />
		<property name="queryDao" ref="queryDao" />
	</bean>



public class BaseService {
    protected BaseDao baseDao;
    protected PageQueryDao pageQueryDao;
    protected QueryDao queryDao;
    
    protected Log log = LogFactory.getLog(getClass());
    /**
     * @param dao
     *            The dao to set.
     */
    public void setBaseDao(BaseDao dao) {
        this.baseDao = dao;
    } 

    public void setPageQueryDao(PageQueryDao pageQueryDao) {
		this.pageQueryDao = pageQueryDao;
	}

	public void setQueryDao(QueryDao queryDao) {
		this.queryDao = queryDao;
	}

}



以上是我的代码 !!!!!

ApplicationContext context = new ClassPathXmlApplicationContext("xms-web.xml");
	BaseService bs = (BaseService) context.getBean("baseService");
if(baseDao==null){
   System.out.print("==========================");
}


总是 打印 ==========================


谁能指点指点
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics