在Spring中使用自定义Hibernate命名策略
2013-09-05 13:01
127 查看
先说一下结果 ,只需要在applictioncontext.xml中配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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-2.5.xsd"> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> <property name="namingStrategy"> <bean class="com.yt17lu.ytbdqn.util.MyNamingStrategy"></bean> </property> </bean> </beans>
通过sessionFactory的namingStrategy注入属性就可以了
以下是自己的分析过程
我为了不在web容器中运行,自己new ContextLoad();
然后调用initWebApplicationContext(ServletContext ctx); 获得Spring容器
但ServletContext 容器有要先初始化, 所以创建了自己的SerlvetContext ,也就是Mock对象
(实际上 在SringTest框架中提供了MockWebApplicationContext
当后来想了一下 实际上没有这个必要,完全可以直接创建ApplicationContext 来进行测试的。SessionFactory 的创建过程与容器无关。
当然进入这种思路也是有原因的,就是该方法原本是 Configuration的方法setNamingStrategy()
阅读更多
相关文章推荐
- 自定义Spring注解bean的命名策略
- spring-data-jpa 下自定义命名策略
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(四):使用 命名空间 简化配置
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(四):使用 命名空间 简化配置
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(四):使用 命名空间 简化配置
- 【spring boot hibernate】hibernate命名策略spring.jpa.hibernate.naming-strategy不起作用
- 自定义Spring注解bean的命名策略
- 问题7:当使用jpa操作数据库的时候,插入数据到数据库使用主键自增策略时候报错:Springboot-jpa Table 'sell.hibernate_sequence' doesn't exist
- 80. Hibernate 5.0命名策略使用naming-strategy 不起作用【从零开始学Spring Boot】
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(四):使用 命名空间 简化配置
- 自定义Spring注解bean的命名策略
- 使用struts+spring+hibernate 组装web应用
- Web Service 中的身份验证策略--使用自定义SOAP 标题
- Web Service 中的身份验证策略--使用自定义SOAP 标题
- 使用struts+spring+hibernate 组装web应用
- 使用myeclipse集成struts,hibernate,spring的一个示例程序(转贴)
- struts+spring+hibernate架构中数据对象(PO,POJO,FormBean)的使用心得
- 使用open source产品组装你的web应用架构(struts+spring+hibernate)
- 使用Spring+Hibernate实现Oracle数据库BlOB数据类型的读写
- 使用struts+spring+hibernate 组装web应用