我正在开发我的第一个 Seam + Android 应用程序,我正面临一些预期的新场景。
现在专门针对这个应用程序,我决定不保留任何状态,因为可能 80% 到 90% 的 REST 服务上的服务器调用将专门做一个简单的同步,而客户端已经消失了一段时间,所以有(可能) 在服务器端为这些调用保留任何状态毫无意义。
好吧,有一个特定的例程,我需要将设备发送到服务器端的对象持久化,并且该对象绑定到特定用户(我认为这是一个非常常见的场景)。
所以有一些代码可以说明。
Home 界面有一个由 Seam 注入的用户:
@Name("pesoHome")
public class PesoHome extends EntityHome<Peso> {
private static final long serialVersionUID = 6087763635317971234L;
@In
User user;
比我们需要一个使用这个主界面的休息服务:
public class PesoRest{
@Logger
Log log;
@In(create = true)
UserPesquisa userPesquisa;
@In(create = true)
PesoHome pesoHome;
@POST
@Path("/cadastrar/{userEmail}")
@Consumes(MediaType.APPLICATION_JSON)
public Response cadastraPeso(@PathParam("userEmail") String email, String jsonString)
{
String json = jsonString;
System.out.println("String jSon no servidor ==>> " + json);
而且由于主界面中的用户注入,在运行时会触发以下错误:
Caused by: org.jboss.seam.InstantiationException: Could not instantiate Seam component: pesoHome
at org.jboss.seam.Component.newInstance(Component.java:2144)
... 46 more
Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: pesoHome.user
请注意,在请求的主体中,JSon 对象带来了有关此用户的信息,允许使用同样注入的 userPesquisa 引用来恢复此用户。我知道我可以有一种不同的方法,我可以构建一个不引用用户的接缝组件,而不是在其中构建用户并将其放置在一个新的对话中,然后注入我需要的主引用,但是......
我想知道可能应该有一些更标准的方法,因为这是一种常见的情况。有什么建议么?:)
[]s