spring-roo 2.0 Spring Webflow Persistence Best Practise



我在使用 Spring Roo 2.0.0.RC2 在网络流中持久化实体时遇到问题。

使用 Roo 2.0,我生成了一个应用程序,该应用程序应在 webflow 结束时注册用户。

这是我的 roo 命令:

entity jpa --class ~.model.AppUser --serializable 
field string --fieldName username --notNull
web flow --flowName registrationProcess --class ~.RegistrationProcessFormBean`

这是我的流程.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="http://www.springframework.org/schema/webflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" start-state="create-appuser" xsi:schemaLocation="http://www.springframework.org/schema/webflow                           http://www.springframework.org/schema/webflow/spring-webflow-2.4.xsd">
<persistence-context />
<on-start>
<set name="flowScope.registrationProcessFormBean" value="new de.xx.www.training.RegistrationProcessFormBean()"/>
<set name="flowScope.appUser" value="new de.xx.www.training.model.AppUser()"/>
</on-start>

<view-state id="create-appuser" model="appUser" view="registrationprocess/create-appuser">
	<transition on="success" to="end-state" />
</view-state> 
<end-state id="end-state" view="registrationprocess/end-state" commit="true"/>
	
</flow>

注意:我知道最好使用 dto 而不是实体。目前,我只是想找到一种简单的方法来保留实体AppUser。

我的问题:

  1. 如何持久化实体?是否可以使用生成的存储库,例如AppUserRepository?(它不可序列化。
  2. 如果需要,如何在 Roo 2.0 的 flowRegistry 中配置 HibernateFlowExecutionListener?

请指教。提前感谢!

更新 02/05/2019

我按照建议做了。

<on-start>
<set name="flowScope.appUser" value="new de.test.model.AppUser()"/>
</on-start>
<!-- A sample view state -->
<view-state id="view-state-1" model="appUser" view="registrationprocess/view-state-1">
<transition on="success" to="view-state-2">
<evaluate expression="appUserServiceImpl.save(appUser)" result="flowScope.appUser" />
</transition>
</view-state>

结果:

org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 19): Method call: Method save(de.test.model.AppUser) cannot be found on de.test.service.impl.AppUserServiceImpl$$EnhancerBySpringCGLIB$$10b2028b type

我做错了什么?

该方法存在。

public class AppUserServiceImpl implements AppUserService {
public AppUser save(AppUser entity) {
return getAppUserRepository().save(entity);
}

谢谢你的一些提示。

更新 02/06/2019

作为解决方法,我在pom中禁用了spring-boot-devtools.xml(见 https://github.com/spring-projects/spring-boot/issues/7912)。

首先定义您的实体并生成存储库和服务层:

entity jpa --class ~.model.MyBean --serializable
repository jpa --all --package ~.repository
service --all --apiPackage ~.service.api --implPackage ~.service.impl

现在,您的服务 Bean (myBeanServiceImpl) 在上下文中可用。

您可以使用它在流中保存实体,如下所示:

<view-state id="view-state-1" view="gocluster/view-state-1" model="basics">
<transition on="success" to="view-state-2">
<evaluate expression="myBeanServiceImpl.save(basics)" result="flowScope.someObjectData" />
</transition>
</view-state>

最新更新