由于某些CGLIB结界,Grails动作不会在测试环境中触发

时间:2013-07-25 14:05:00

标签: grails cglib

我有一个带有多个页面和控制器的grails应用程序。虽然某些操作正常工作且gsp页面正确呈现,但由于某些CGLIB相关错误,其中一些操作未呈现。当我想运行/ panel / create action时,这是我的异常:

processing request: [GET] /panel/create
Template not found for name [form] and path [/panelController$$EnhancerByCGLIB/_form.gsp]. Stacktrace follows:
org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error proc                                                                                                                                                             essing GroovyPageView: Template not found for name [form] and path [/panelContro                                                                                                                                                             ller$$EnhancerByCGLIB/_form.gsp]
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(Pag                                                                                                                                                             eFragmentCachingFilter.java:195)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter                                                                                                                                                             .java:63)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.                                                                                                                                                             java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor                                                                                                                                                             .java:615)
    at java.lang.Thread.run(Thread.java:722)

_form.gsp:

<div class="fieldcontain ${hasErrors(bean: panelInstance, field: 'unitProtocol', 'error')} required">
<label for="unitProtocol">
    <g:message code="panel.checkupPanel.label" />
    <span class="required-indicator">*</span>
</label>

<g:if test="${panelInstance?.unitProtocol}">
    <g:select id="unitProtocol" name="unitProtocolId" from="${unitProtocolService.getNonDefinedCheckUpPanelUnitProtocols() + panelInstance?.unitProtocol }" optionKey="code" value="${panelInstance?.unitProtocol?.code}" class="many-to-one"/>
</g:if>
<g:else>
    <g:select id="unitProtocol" name="unitProtocolId" from="${unitProtocolService.getNonDefinedCheckUpPanelUnitProtocols()}" optionKey="code" value="${panelInstance?.unitProtocol?.code}" class="many-to-one"/>
</g:else>
</div>
        <div class="fieldcontain panelGrid grid">
            <table id="panelGrid"></table>
        </div>

        <div id="panelPager"></div>

<script type="text/javascript" src="${resource(dir: 'js', file: 'panel.js')}"></script>

create.gsp

<%@ page import="akum.main.pricingcontract.Panel" %>
<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main">
    <g:set var="entityName" value="${message(code: 'panel.label', default: 'Panel')}" />
    <title><g:message code="default.create.label" args="[entityName]" /></title>
</head>
<body>
    <div id="create-panel" class="content scaffold-create" role="main">
        <h1><g:message code="default.create.label" args="[entityName]" /></h1>
        <g:if test="${flash.message}">
        <div class="message" role="status">${flash.message}</div>
        </g:if>
        <g:hasErrors bean="${panelInstance}">
        <ul class="errors" role="alert">
            <g:eachError bean="${panelInstance}" var="error">
            <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
            </g:eachError>
        </ul>
        </g:hasErrors>
        <g:form action="save" >
            <fieldset class="form">
                <g:render template="form"/>
            </fieldset>
            <fieldset class="buttons">
                <g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />
            </fieldset>
        </g:form>
    </div>
</body>

PanelController:

package akum.main.pricingcontract

import javax.persistence.Transient;

import grails.converters.JSON

import org.springframework.dao.DataIntegrityViolationException
import org.springframework.transaction.annotation.Transactional;

class PanelController {

def fpProviderService
def unitProtocolService

static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

def index() {
    redirect(action: "list", params: params)
}

def list(Integer max) {
    params.max = Math.min(max ?: 10, 100)
    removeSessionParameters()
    [panelInstanceList: Panel.list(params), panelInstanceTotal: Panel.count()]
}

def create() {
    session.activePanelOperation = "create"
    [panelInstance: new Panel(params)]
}
}

视图是使用grails scaffolding创建的,只涉及很少的业务。

我的Grails版本是2.1.1。

1 个答案:

答案 0 :(得分:0)

事实证明,我的控制器上有@Transactional注释保存方法。我删除它时解决了这个问题。