生产环境中的Grails服务返回Null

时间:2014-09-09 12:56:00

标签: grails grails-2.4

我使用的是Grails 2.4.3,我的服务只在生产环境中返回null。如果我在Dev环境中运行它,服务会正确响应。即使我使用开发生成war文件也可以,但如果我使用生产环境(默认的grails war)生成war文件,该服务将返回null。我不确定在环境影响服务的地方会发生什么?

我只是通过这种方式发现了一个特定服务的问题。项目中的所有其他服务似乎在所有环境中都能正常工作。

- UPDATE-- 详细说明有问题的服务:该服务确实进行了一些数据库查询和保存(在会话中获取一些信息并保存)。它在课堂上标有@Transactional。它还按惯例注入两个辅助服务(包括sessionFactory)(def sessionFactory; def otherService;)

我也试过从应用程序上下文中获取bean,然后我找到了#34; Bean找不到"

1 个答案:

答案 0 :(得分:0)

从事物的声音来看,它与你的注射有关..

  1. 我会跑
  2. grails run-war

    来自开发 - 看看这是否会重现同样的问题:

    1. 将应用程序数据库置于调试模式以查看它是否与数据库相关:
    2. How to log SQL statements in Grails

      如果这不能解决问题,下一次尝试将实际应用程序置于调试模式

      http://grails-dev.blogspot.co.uk/2012/09/setting-up-log4j-configuration-in.html

      1. 这肯定是一个服务,而不是一个常规的src文件或什么,以便将服务注入您可以尝试的其他调用:
      2. conf / spring / resources.groovy

        为src / groovy文件创建一个条目:在本例中为GetDownloadConfig 定义注射:

        getDownloadConfig(GetDownloadConfig) {
                        grailsApplication = ref('grailsApplication')
                        dnsService = ref('dnsService')
                        jobReplaceService= ref('jobReplaceService')
                        jenkinsService= ref('jenkinsService')
                    }
        

        然后在

        class GetDownloadConfig {
            def jenkinsService
            def dnsService
            def jobReplaceService
            def grailsApplication
        
        
             // Or alternative method using holders - 
            //def grailsApplication = Holders.grailsApplication.mainContext.getBean 'grailsApplication'
            //def dnsService = Holders.grailsApplication.mainContext.getBean 'dnsService'
            //def jobReplaceService= Holders.grailsApplication.mainContext.getBean 'jobReplaceService'
            //def jenkinsService= Holders.grailsApplication.mainContext.getBean 'jenkinsService'
        

        这可能也有帮助

        How do you get the sessionFactory in a Grails Geb/Spock test case?

相关问题