автоподводка пружинного боба в верблюжьем процессоре

Я создаю пакет OSGI для работы в контейнере Jboss Fuse 6.1. Проект содержит blueprint.xml (в src / main / resoureces / OSGI-INF / blueprint). Это содержание:

 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:camel="http://camel.apache.org/schema/blueprint"
               xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
               xmlns:cxf="http://cxf.apache.org/blueprint/core"
               xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"

               xsi:schemaLocation="
           http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
             http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
           http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
            http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
     http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd"
    >
<bean id="MyProcessor" class="com.test.MyProcessor" />
          <camelContext trace="false" id="blueprintContext" xmlns="http://camel.apache.org/schema/blueprint">
            <route>
                <from uri="activemq:queue:paymentsqueue?username=admin&amp;password=admin" id="NotificationRoute">
                    <description/>
                </from>
                <log message="The message contains ${body}"/>
                <process ref="MyProcessor"/>
            </route>
        </camelContext>
    </blueprint>

Моя цель - использовать Spring beans в MyProcessor. Это код для MyProcessor:

public class MyProcessor implements Processor {

@Aurowired
private Sender sender;

@Override
public void process(Exchange x) throws Exception {
    log.info("test: " +sender.getSenderId());
}

}

Но это дает мне нулевое исключение. Что я делаю не так?

Это содержимое моего файла конфигурации Spring (я поместил его в src / main / resoureces / META-INF / spring)

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
    <context:annotation-config/>
    <context:component-scan base-package="com.username"/>
<bean id="sender" class="com.username.Sender" scope="prototype">
     <property name="senderId" value="sendername" />
     <property name="password" value="senderpassword" />
</bean>


person Maciavelli    schedule 07.07.2016    source источник
comment
Как правило, можно ли одновременно использовать Spring beans в blueprint beans? Как в моем примере, где маршрут верблюда и процессор созданы с помощью blueprint, но bean-компонент autowiring, созданный spring.   -  person Maciavelli    schedule 07.07.2016


Ответы (1)


Я думаю, что вы не объявили процессор MyProcessor как bean-компонент весной, например

<bean id="myProcessor"
        class="com.test.MyProcessor" />

тогда вы можете использовать его как

<process ref="myProcessor"/>

Так же

@Aurowired
private Sender sender;

должно быть @Autowired (это должна быть опечатка, но указала на нее.)

person Rehan    schedule 07.07.2016
comment
Да, я ошибся при копировании кода выше. Этот bean-компонент объявлен в blueprint. Я отредактировал. - person Maciavelli; 07.07.2016