Grails 3.1.0.RC1如何获取sessionFactory?

时间:2016-01-08 13:31:13

标签: grails sessionfactory grails-3.0

我将项目从grails 3.0.11迁移到grails 3.1.0.RC1并得到错误

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 48 common frames omitted

我该怎么办?感谢名单

1 个答案:

答案 0 :(得分:2)

我不知道3.1.X,但在2.4.X和3.0.11中,我使用的是这样的:

def grailsApplication = Holders.getGrailsApplication()
def sessionFactory = grailsApplication?.mainContext?.sessionFactory

这在单元测试中不起作用,但我不需要会话工厂。它确实可用于开发,生产和集成测试。