开发者

Ignoring spring bean injection if class not avaliable

开发者 https://www.devze.com 2023-01-22 16:04 出处:网络
We have set of common spring application context configuration files. Depending on the deployment (We deploy one module or multiple module), bean injection classes will change e.g.

We have set of common spring application context configuration files. Depending on the deployment (We deploy one module or multiple module), bean injection classes will change e.g.

<bean id="tagService" class="com.ekaplus.servi开发者_如何转开发ce.tag.TagService" >

     <property name="mdmTagService" ref="mdmTagService" />

      <property name="physicalTagService" ref="physicalTagService" />
  </bean>

physcialTagService bean will be available if physical module is deployed else it won't be available. I don't want to change the common configuration for each deployment. Is there any way in spring to ignore certain beans injection if class is not available.


Well if you just use autowiring by name or by type, Spring won't autowire anything it can't find:

<bean class="foo.bar.Phleem" autowire="byType" />


You could also use a parent-child implementation by using "abstract", ie

<bean id="tagServiceParent" class="com.ekaplus.service.tag.TagService" abstract="true">
<property name="implementedTagService" ref="defaultTagService" />
..other common properties here...
</bean>

<bean id="tagService" parent="tagServiceParent">
<property name="implementedTagService" ref="mdmTagService" />
</bean>

But im not sure how you're implementing, so it might not suit your needs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号