传递“HardCoded”构造函数Arg类< T>通过Spring Config来bean [英] pass "HardCoded" Constructor Arg Class<T> to bean via Spring Config

查看:156
本文介绍了传递“HardCoded”构造函数Arg类< T>通过Spring Config来bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通用类型,我注入服务。由于泛型在Java中的实现方式,我需要一个构造函数arg(或属性setter)来保存泛型类型参数的Class信息。

I have a generic type that I am injecting into a service. Because of the way generics are implemented in Java, I need to have a constructor arg (or property setter) that holds the Class information of the generic type parameter.

我的问题是 - 我可以通过属性注入或指定构造函数arg传入带弹簧的Class实例吗?

My question is -- Can I, via property injection or specifying a constructor arg, pass in an instance of Class with spring?

我知道运行时间之前的T类型所以我特别知道Type参数是什么。

I DO know the type of T before run time so I know specifically what the Type parameter will be.

我认为它看起来像这样:

I was thinking it would look something like this:

<bean id="dataMartService" class="com.someclass">
    <constructor-arg value="java.lang.class<com.someotherclass>" />
</bean>

我完全不知道应该怎么做?

Am I completely off in how this should happen?

推荐答案

尝试:

<bean id="dataMartService" class="com.someClass">
    <constructor-arg>
        <value type="java.lang.Class">someotherclass</value>
    </constructor-arg>
</bean>

这篇关于传递“HardCoded”构造函数Arg类&lt; T&gt;通过Spring Config来bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆