在Spring中使用自定义Hibernate命名策略

阅读更多

先说一下结果 ,只需要在applictioncontext.xml中配置



	
		
		
		
			
		
	

  通过sessionFactory的namingStrategy注入属性就可以了

 

以下是自己的分析过程

     我为了不在web容器中运行,自己new ContextLoad();
然后调用initWebApplicationContext(ServletContext ctx); 获得Spring容器

但ServletContext 容器有要先初始化, 所以创建了自己的SerlvetContext ,也就是Mock对象

(实际上 在SringTest框架中提供了MockWebApplicationContext

当后来想了一下 实际上没有这个必要,完全可以直接创建ApplicationContext 来进行测试的。SessionFactory 的创建过程与容器无关。

当然进入这种思路也是有原因的,就是该方法原本是 Configuration的方法setNamingStrategy()

 

你可能感兴趣的:(Spring,Hibernate,NamingStrategy,Configuration)