在spring配置中指定的路由中使用camel组件

时间:2015-09-08 17:59:35

标签: spring apache-camel sftp

我有以下sftp驼峰组件配置:

@Configuration
public class FtpCamelComponent {

    @Value("${SFTP_HOST}")
    private String sftpHost;

    @Value("${SFTP_KNOWNHOST}")
    private String sftpKnownHost;

    @Value("${SFTP_KEY}")
    private String sftpKey;

    @Value("${SFTP_USER}")
    private String sftpUser;

    @Value("{SFTP_DIRECTORY}")
    private String sftpFileDirectory;

    @Bean
    public SftpConfiguration sftpConfiguration(){
        SftpConfiguration sftpConfiguration = new SftpConfiguration();
        sftpConfiguration.setUsername(sftpUser);
        sftpConfiguration.setHost(sftpHost);
        sftpConfiguration.setKnownHostsFile(sftpKnownHost);
        sftpConfiguration.setPrivateKeyFile(sftpKey);
        sftpConfiguration.setDirectory(sftpFileDirectory);
        return sftpConfiguration;
    }

    @Bean
    public SftpEndpoint sftpEndpoint(SftpConfiguration sftpConfiguration){
        SftpEndpoint sftpEndpoint = new SftpEndpoint();
        sftpEndpoint.setConfiguration(sftpConfiguration);
        sftpEndpoint.setEndpointUriIfNotSpecified("sftp");
        return sftpEndpoint;
    }

    @Bean
    public SftpComponent sftpComponent(SftpEndpoint sftpEndpoint){
        SftpComponent sftpComponent = new SftpComponent();
        sftpComponent.setEndpointClass(sftpEndpoint.getClass());

        return sftpComponent;
    }
}

我将组件添加到我的驼峰上下文中:

@Configuration
@Import({FtpCamelComponent.class,
        SftpCamelRoute.class})
public class SftpCamelContext extends CamelConfiguration {

    @Autowired
    SftpComponent sftpComponent;


    @Bean(name = "sftpCamelContext")
    protected CamelContext createCamelContext() throws Exception {
        SpringCamelContext camelContext = new SpringCamelContext();
        camelContext.setApplicationContext(getApplicationContext());
        camelContext.addComponent("sftp", sftpComponent);
        return camelContext;
    }
}

为什么我不能在我的骆驼路线中使用sftp:因为我已经配置它并将它添加到我的驼峰上下文中?

 @Bean(name = "FileToSftp")
    public RouteBuilder fileToSFTP(){
        return new RouteBuilder() {
            public void configure() {
                from("direct:fileToSftp")
                        .to("file:export/b1?fileName=export.csv")
                        .setHeader("CamelFileName", constant("export.csv"))
                        .to("sftp://dev@localhost:/export/in/?knownHostsFile=key/knownhost&privateKeyFile=key/id_rsa.pub&localWorkDirectory=export/b1&download=false");
            }
        };
    }

0 个答案:

没有答案