Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OSGi静态字段_Java_Spring_Osgi_Htmlunit_Blueprint - Fatal编程技术网

Java OSGi静态字段

Java OSGi静态字段,java,spring,osgi,htmlunit,blueprint,Java,Spring,Osgi,Htmlunit,Blueprint,我需要创建一个将类实例作为构造函数参数的bean。该类实例的有用值由该类作为静态字段创建 具体来说,我正在尝试从HtmlUnit创建WebClient bean 您可以看到WebClient采用了一个无参数构造函数(不需要),以及一个采用BrowserVersion实例的构造函数。 BrowserVersion将有用的实例定义为静态字段,例如:CHROME、FIREFOX\u 24、INTERNET\u EXPLORER\u 11 我需要在Aries Blueprint bean中引用其中一个

我需要创建一个将类实例作为构造函数参数的bean。该类实例的有用值由该类作为静态字段创建

具体来说,我正在尝试从HtmlUnit创建WebClient bean

您可以看到WebClient采用了一个无参数构造函数(不需要),以及一个采用BrowserVersion实例的构造函数。

BrowserVersion将有用的实例定义为静态字段,例如:CHROME、FIREFOX\u 24、INTERNET\u EXPLORER\u 11

我需要在Aries Blueprint bean中引用其中一个BrowserVersion实例

以下是blueprint设置的外观:

<bean id="webClient" class="com.gargoylesoftware.htmlunit.WebClient">
    <argument>??</argument>
</bean>

在浏览器上


你知道我在这两方面做错了什么吗?

通过使用助手方法解决了这个问题

<bean id="webClient" class="com.stackoverflow.HtmlUnitHelper" factory-method="getChromeClient" />
也许有更好的解决方案,但这是可行的

<bean id="webClient" class="com.gargoylesoftware.htmlunit.WebClient">
    <argument>
        <bean class="com.gargoylesoftware.htmlunit.BrowserVersion">
            <argument index="0" type="java.lang.String" value="Netscape" />
            <argument index="1" type="java.lang.String" value="5.0 (Windows)" />
            <argument index="2" type="java.lang.String" value="Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0" />
            <argument index="3" type="java.lang.Float"  value="24.0" />
        </bean>
    </argument>
</bean>
<bean id="webClient" class="com.stackoverflow.HtmlUnitHelper" factory-method="getChromeClient" />
public static WebClient getChromeClient() {
    return new WebClient(BrowserVersion.CHROME);
}