简体   繁体   English

使用JBoss Seam进行构造器注入

[英]Constructor injection with JBoss Seam

I'm new to JBoss Seam. 我是JBoss Seam的新手。 I'd like to know how do I instantiate a class without a no-arg constructor in JBoss Seam. 我想知道如何在JBoss Seam中没有no-arg构造函数的情况下实例化一个类。

I have to instantiate JsonPrimitive (from Google Gson framework) that has just constructors which receive arguments. 我必须实例化JsonPrimitive(来自Google Gson框架),它只有接收参数的构造函数。

How the regular code would be: 常规代码将如何:

import com.google.gson.JsonPrimitive;
...
JsonPrimitive jsonPrimitive = new JsonPrimitive(myobject.toString())

Trying to transport the code to Seam: 尝试将代码传输到Seam:

import com.google.gson.JsonPrimitive;
..
@In(create=true)
JsonPrimitive jsonPrimitive

But this kind of thing in Seam(shown above) will not help me. 但是Seam中的这种事情(如上所示)对我没有帮助。 I have to pass an argument in the constructor to instantiate the class. 我必须在构造函数中传递一个参数以实例化该类。

How could I tell Seam to use an argument in the constructor when instantiating an object to be injected? 实例化要注入的对象时,如何告诉Seam在构造函数中使用参数?

Thanks! 谢谢!

You should be able to use the factory annotation: 您应该能够使用工厂注释:

@Factory("jsonPrimitive")
public void loadJsonPrimitive()
{
    jsonPrimitive = new JsonPrimitive(myobject.toString())
}

See the Seam documentation for @Factory 参见@Factory的Seam文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM