2016-08-06 21 views
1

In meiner Camel und Spring Boot-Anwendung habe ich eine einfache Route: Ordner-> Prozessor-> Ordner.@Service- und @Repository-Beans initialisieren nicht im Frühjahr boot und Apache camel

Im Prozessor sind der Service und das Repository immer null. In den Testklassen sind diese nicht null.

@Override 
public void configure() throws Exception 
{ 
    from("file:input") 
    .log("from file") 
    .process(new MyProcessor()) 
    .to("file:destination") 
    .log("to destination")` 
    .end(); 
} 

Ich vermisse etwas. Warum sind die Repository- und Service-Beans im Prozessor null, funktionieren sie aber in den Testklassen einwandfrei?

Antwort

1

Sie erstellen manuell einen Prozessor über new MyProcessor(), was bedeutet, dass Spring die Abhängigkeiten für Sie nicht autowire.

sollten Sie Camel Bean support statt:

@Override 
public void configure() throws Exception 
{ 
    from("file:input") 
    .log("from file") 
    .bean("myProcessor") 
    .to("file:destination") 
    .log("to destination")` 
    .end(); 
} 

Oder, wenn Ihr MyProcessor bean implementiert Camel Processor, könnten Sie so etwas tun:

@Autowired 
private MyProcessor processor; 

@Override 
public void configure() throws Exception 
{ 
    from("file:input") 
    .log("from file") 
    .processor(processor) 
    .to("file:destination") 
    .log("to destination")` 
    .end(); 
}