在Tomcat上运行时,Grails服务注入失败

时间:2014-06-08 17:11:56

标签: tomcat grails

我正在尝试部署我在Tomcat 7(CentOS 6)上使用IntelliJ(Windows)开发的小应用程序。一切都在我的开发机器上运行。我使用run-app和prod run-app运行它。

我的应用有1个使用服务的控制器(def logService)。我在服务目录(class LogService)中定义了我的服务。在我的开发系统上运行时,我的控制器中的logService不为null,但是当我部署它时(使用war文件),logService为null。

这是我的控制器:

package LogViewer

import grails.transaction.Transactional

import java.text.SimpleDateFormat

@Transactional(readOnly = true)
class OlrBrowserLogController
{
    def olrBrowserLogService

    def index() {
        def startDate = params.startDate

        Calendar now = Calendar.getInstance()
        if (startDate == null)
            now.add(Calendar.MONTH, -2)
        else {
            SimpleDateFormat sdf = new SimpleDateFormat('M/d/yyyy');
            now = sdf.parse(startDate).toCalendar()
        }

        def c = OlrBrowserLog.createCriteria()
        def rawLogEntries = c.list {
            gt("createdDate", now.getTime())
            order("createdDate", "desc")
        }

        def parsedLogEntries = []

        for (logEntry in rawLogEntries) {
            def parsedLogEntry = olrBrowserLogService.parseAgentString(logEntry)

            parsedLogEntries.add(parsedLogEntry)
        }

        return [parsedLogEntries: parsedLogEntries, startDate: now.getTime().format("M/d/y")]
    }
}

这是我的服务:

package logviewer

import LogViewer.OlrBrowserLog
import LogViewer.bLog
import grails.transaction.Transactional
import net.sf.uadetector.ReadableUserAgent
import net.sf.uadetector.UserAgentStringParser
import net.sf.uadetector.service.UADetectorServiceFactory

@Transactional
class OlrBrowserLogService {
    def parseAgentString(OlrBrowserLog olrBrowserLogInstance)
    {
        // Get an UserAgentStringParser and analyze the requesting client
        UserAgentStringParser parser = UADetectorServiceFactory.getResourceModuleParser();
        ReadableUserAgent agent = parser.parse(olrBrowserLogInstance.browserUserAgent);

        def bLogInstance = new bLog()
        bLogInstance.userEmailAddress = olrBrowserLogInstance.wcUserEmailAddress
        bLogInstance.ipAddress = olrBrowserLogInstance.ipAddress
        bLogInstance.createdDate = olrBrowserLogInstance.createdDate.format("M/d/y h:mm a")
        bLogInstance.browserUserAgent = olrBrowserLogInstance.browserUserAgent
        bLogInstance.screenWidth = olrBrowserLogInstance.screenWidth
        bLogInstance.screenHeight = olrBrowserLogInstance.screenHeight
        bLogInstance.browserWidth = olrBrowserLogInstance.browserWidth
        bLogInstance.browserHeight = olrBrowserLogInstance.browserHeight
        bLogInstance.device = agent.deviceCategory.name
        bLogInstance.operatingSystem = agent.operatingSystem.name
        bLogInstance.browser = agent.name
        bLogInstance.version = agent.versionNumber.toVersionString()

        return bLogInstance
    }
}

我打开了一些日志记录,我收到了这条消息:

  

2014-06-09 07:52:23,904 [http-bio-8080-exec-2] WARN commons.GrailsApplicationFactoryBean - 找不到名称为[logviewer.OlrBrowserLogService]的类,因此未加载。可能的空类或脚本定义?

1 个答案:

答案 0 :(得分:0)

此问题的最可能原因是您要么在OlrBrowserLogService上缺少包声明,要么包定义与目录结构不匹配。验证您的包是否正确,然后再次尝试部署。