我一直试图将我的一些grails 2代码移植到grails 3.这个特定的代码使用grails-webflow插件(仅支持grails 2.x;它现在被破坏,因为在grails core中进行了一些检修)
所以我决定在我的应用程序中直接使用spring webflow。我已经能够做基本的管道。那是我的设置 * webflow的应用程序上下文 *创建了流程工厂和所有 *写了流程xml。 *创造了其他必要的豆类。
现在,当我点击映射到我的流的url时,我可以看到我的.gsp页面正在渲染。但问题是,它没有解决布局问题。并且页面没有任何样式/布局。我缺少什么?
这是我的gsp page
。
<html>
<head>
<title><g:brandedTitle/> - Repository Database: Administrator</title>
<meta content="main" name="layout"/>
<script type="text/javascript" src="${assetPath(src: 'da.js')}"></script>
....
....
这就是我为webflow做的管道。
@Configuration
@ComponentScan
class InstallRepositoryWebflow extends AbstractFlowConfiguration {
@Autowired
GroovyPagesTemplateEngine groovyPagesTemplateEngine;
@Autowired
GroovyPageLocator groovyPageLocator;
@Autowired
GrailsLayoutViewResolver grailsLayoutViewResolver;
@Bean
public FlowDefinitionRegistry flowRegistry() {
return getFlowDefinitionRegistryBuilder(flowBuilderServices())
// type on browser localhost:<port>/<context-path>/hitMeToInvokeThisFlow to invoke this flow.
.addFlowLocation("/WEB-INF/flows/install-repository.xml", "installrep/install")
.build();
}
@Bean
public FlowExecutor flowExecutor() {
return getFlowExecutorBuilder(flowRegistry()).build();
}
@Bean
public FlowBuilderServices flowBuilderServices() {
return getFlowBuilderServicesBuilder()
.setViewFactoryCreator(viewFactoryCreator())
.build();
}
@Bean
public ViewFactoryCreator viewFactoryCreator() {
List<ViewResolver> resolvers = new ArrayList<>(1);
resolvers.add(gspViewResolver());
resolvers.add(grailsLayoutViewResolver);
ViewFactoryCreator creator = new MvcViewFactoryCreator();
creator.setViewResolvers(resolvers);
return creator;
}
@Bean
ViewResolver gspViewResolver() {
GroovyPageViewResolver innerGspViewResolver = new GroovyPageViewResolver(groovyPagesTemplateEngine, groovyPageLocator);
//innerGspViewResolver.setAllowGrailsViewCaching(!gspReloadingEnabled || viewCacheTimeout != 0);
//innerGspViewResolver.setCacheTimeout(gspReloadingEnabled ? viewCacheTimeout : -1);
return innerGspViewResolver;
}
}
这是resource.groovy
flowHandlerAdapter(FlowHandlerAdapter) {
flowExecutor = ref("flowExecutor");
}
flowHandlerMapping(FlowHandlerMapping) {
flowRegistry = ref("flowRegistry");
}
问题为什么我的布局没有呈现?我错过了什么?
答案 0 :(得分:1)
最后我找到了这个问题的答案。如果我使用SitemeshLayoutViewResolver layoutViewResolver
,而不是创建自定义解析程序GroovyPageViewResolver innerGspViewResolver = new GroovyPageViewResolver(groovyPagesTemplateEngine, groovyPageLocator);
,那么我的问题就解决了。所以基本上它必须是这样的。
@Bean
ViewResolver gspViewResolver() {
return jspViewResolver;
}
@Autowired
GrailsViewResolver jspViewResolver
这是示例项目here,以防有人正在寻找工作示例。
一旦我完成了这一切,我遇到了一个非常奇怪的问题。当我从intellij运行应用程序时,应用程序的Webflow部分正常工作。但是当我使用war
任务创建gradlew assemble
时,我总是在应用上获得/错误页面。在日志中,它显示No mapping found for HTTP request with URI * in DispatcherServlet with name 'grailsDispatcherServlet'
。
显然,我试图创建的bean不在那里。为了解决这个问题,我放弃了基于注释的配置,并将resources.xml文件放在grails-app/conf/spring/
目录中。这解决了战争的问题。这是我的配置文件。
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress SpringFacetInspection -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:webflow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.4.xsd">
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path="/WEB-INF/flows/install-repository.xml" id="installrep/install"/>
</webflow:flow-registry>
<webflow:flow-executor id="flowExecutor" />
<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator"/>
<bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers" ref="resolvers"/>
</bean>
<bean id="resolvers" class="java.util.ArrayList">
<constructor-arg>
<list>
<ref bean="jspViewResolver" />
</list>
</constructor-arg>
</bean>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor" />
</bean>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry"/>
<property name="order" value="0"/>
</bean>
</beans>