您的位置:首页 > 其它

配置 OWA 下次登录时更改密码

2012-03-28 14:54 309 查看
上面一篇文章讲到了集成hibernate4,主要是就如何在spring3的环境下如何配置的问题,突然发现,hibernate的映射文件在sessionFactory的配置内,也和hibernateProperties的配置在一起,sessionFactory是hibernate的核心配置,开发人员不应该也没必要总去看到这个文件,而开发人员又必须添加很多的entity的映射文件。在这个操作中,如果有任何的误操作,损失还是满大的,与是如何把经常会频繁操作的hibernate-mapping内容从SessionFactory的配置中分离出去就成了一个良好的框架设计的当务之急的选择。于是动手,其实很简单,在spring的ioc环境下,这一些都变的是那么的优雅。

首先:编写IMapping接口:

public interface IMapping
{
public String[] getMappingResources();
}

然后写实现:

public class HibernateMappingImpl implements IMapping
{
private String[] mappingResources;

public String[] getMappingResources()
{
return mappingResources;
}

public void setMappingResources(String[] mappingResources)
{
this.mappingResources = mappingResources;
}
}

然后编写类去继承LocalSessionFactoryBean:

public class XKLocalSessionFactoryBean extends LocalSessionFactoryBean
{
private IMapping iMapping;

public IMapping getiMapping()
{
return iMapping;
}

public void setiMapping(IMapping iMapping)
{
this.iMapping = iMapping;
super.setMappingResources(iMapping.getMappingResources());
}
}

到这大家也许都看明白了。

下面将这些类配置到相关配置中去:

sessionFactory的配置改为:

<bean id="sessionFactory" class="com.xk.commons.config.XKLocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="iMapping" ref="hibernateMapping">
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.jdbc.use_scrollable_resultset">false</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
</props>
</property>
</bean>

对应的已经换成我们自己实现的com.xk.commons.config.XKLocalSessionFactoryBean, 而原来的 mappingResources 的属性配置,也换成了<property name="iMapping" ref="hibernateMapping"> 引用的是个类,就是我们自己定义的那个IMapping接口的类,我们单独的新建一个文件: hibernate-mapping.xml,以后的实体映射的配置,就不用去核心的配置里添加修改了,就都到这个项目级别的文件中去修改,下面看这个类的配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> 
<bean id="hibernateMapping" class="com.xk.commons.config.HibernateMappingImpl">
<property name="mappingResources">
<list>
<value>com/xk/model/XkBaseCity.hbm.xml</value>
<value>com/xk/model/XkBaseProvince.hbm.xml</value>
<value>com/xk/model/XkSystemDate.hbm.xml</value>
<value>com/xk/model/XkTrain.hbm.xml</value>
</list>
</property>
</bean>
</beans>

看看,干净明了,给开发人员培训的时候,可以叫他们忽略掉,那些核心配置的内容,只需要叫他们知道开发的规则,和如何做就ok了,可以大大的降低开发人员的学习成本和技术要求。
本文出自 “My Joy is my joy ~” 博客,转载请与作者联系!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: