Apache Camel - Spring Web App - Camel Context未在@PostConstruct上启动

时间:2014-09-29 13:23:11

标签: java spring spring-mvc apache-camel

我有一个使用Spring的Apache-Camel Web应用程序。我有一些属性的路线 autoStartup=false所以我可以根据应用程序启动时的一些检查有条件地启动它们。为了做到这一点,我在@PostConstruct init方法中有逻辑。 但是,一旦加载了@PostConstruct方法,CamelContext就已经构建但不是已启动。因此,routeDefinitions尚未加载。所以,如果我做camelContext.startRoute("myRoute")。什么都没发生。另一方面,如果我将此方法公开为Web服务,则路由按预期正常启动。这是我的控制器:

@Controller
public class EntryBean implements CamelContextAware {

    private CamelContext camelContext;

    @PostConstruct
    public void init() {
        //at this point the started property is still false
        //and the camelContext does have any routeDefinitions
        camelContext.startRoute("myRoute");
    }

    @RequestMapping("startRoutes")
    @ResponseBody
    public String startCamelRoutes() {
        //this runs normally when called from the GET request
        camelContext.startRoute("myRoute");
        return "Routes Started Succesfully";
    }

    @Override
    public void setCamelContext(CamelContext camelContext) {
        this.camelContext = camelContext;
    }

    @Override
    public CamelContext getCamelContext() {
        return camelContext;
    }
}

我甚至使用过<bean class="org.example.EntryBean" depends-on="camelContext"/>但仍然没有。

0 个答案:

没有答案