Spring dependency injection with WildFly

落花浮王杯 提交于 2019-12-12 14:14:28

问题


I have a web application (war file) that depends (Maven) on another project (jar file) that uses Spring for dependency injection. So in that other project I have a couple of xml files to declare my beans, in my case business objects. I started using WildFly instead of Tomcat/Jetty and apparently there is that thing called Weld in charge of DI. My web app doesn't use Spring (for now), it's just a simple Jersey RESTful API.
I want my business objects to be injectable (@Inject) in my resources (controllers).

How do I make my beans accessible, meaning how do we mix Spring DI and WildFly DI?

Right now in my web app project I have a WEB-INF/beans.xml file with this:

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:weld="http://jboss.org/schema/weld/beans"
    xsi:schemaLocation="
    http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd
    http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd
    bean-discovery-mode="all">
</beans>

But when I try to deploy, for this code:

@Inject SomeBO myBO;

I get this error:

WELD-001408: Unsatisfied dependencies for type SomeBO with qualifiers @Default

Thanks.

EDIT
I need to import my beans with the xml files, I don't want to annotate them, for instance I have a bo.xml file (Spring beans) that contains such declaration:

    <bean id="com.xxx.bo.SomeBO" parent="com.xxx.bo._AbstractBO">
        <property name="target">
            <bean class="com.xxx.bo.SomeBOImpl">
                <property name="DAO" ref="com.xxx.dao.SomeDAO"/>
            </bean>
        </property>
    </bean>

回答1:


WildFly implements the Java EE Spec which means it provides an implementation for CDI. In WildFly's case it uses the reference implementation which is Weld. There are some tutorials for Java EE 6 that should explain CDI fairly well.

As far as your error, you probably just need to annotate your your SomBO implementation with @Named or a valid CDI annotation to make it a CDI managed bean.



来源:https://stackoverflow.com/questions/27759416/spring-dependency-injection-with-wildfly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!