启动应用程序时无法创建bean

Cannot create bean when start the application

我在创建 bean 时遇到了一些问题,它给出了错误。 有人可以帮助我吗?我将从 sftp 资源中检索文件,并使用 spring 任务调度程序作业读取这些文件。

应用-Config.xml

  <?xml version="1.0" encoding="UTF-8"?>
<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:task="http://www.springframework.org/schema/task"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context-4.0.xsd
                            http://www.springframework.org/schema/tx
                            http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
                            http://www.springframework.org/schema/task 
                            http://www.springframework.org/schema/task/spring-task-4.0.xsd                          
                            http://www.springframework.org/schema/integration   
                            http://www.springframework.org/schema/integration/spring-integration.xsd
                            http://www.springframework.org/schema/integration/sftp
                            http://www.springframework.org/schema/integration/sftp/spring-integration-sftp.xsd">                    


    <context:component-scan base-package="com.canaldigital.tsi.bank" />
    <context:property-placeholder location="classpath:settings.properties" />

    <task:scheduled-tasks scheduler="myScheduler">
        <task:scheduled ref="myBean" method="printMessage" fixed-delay="600000" initial-delay="3000"/>
        <task:scheduled ref="myBean" method="checkStatus" fixed-delay="6000" initial-delay="2000"/>
    </task:scheduled-tasks>

    <task:scheduler id="myScheduler" pool-size="10" />


     <bean id="sftpSessionFactory" class="org.springframework.integration.file.remote.session.CachingSessionFactory">
        <constructor-arg ref="defaultSftpSessionFactory" />
             <property name="sessionCacheSize" value="10"/>
             <property name="sessionWaitTimeout" value="1000"/>     
    </bean>


    <bean id="defaultSftpSessionFactory"
            class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
        <property name="host" value="${sftp.host}"/>
        <property name="username" value="${sftp.username}"/>
        <property name="password" value="${sftp.password}"/>
        <property name="port" value="${sftp.serverPort}"/>

        <!-- <property name="privateKey" value="${sftp.private.keyfile}"/> -->
        <!-- <property name="privateKeyPassphrase" value="${sftp.passphrase}"/> -->

    </bean>

<int-sftp:inbound-channel-adapter id="sftpAdapterAutoCreate"
            session-factory="sftpSessionFactory"
            channel="requestChannel"
            filename-pattern="*.csv"
            remote-directory="/home/oracle/IBSTOBANK/DNB/Norway/Outgoing"
            preserve-timestamp="true"
            local-directory="file:target/foo"
            auto-create-local-directory="true"
            local-filename-generator-expression="#this.toUpperCase() + '.a'"
            local-filter="myFilter"
            temporary-file-suffix=".writing"
            delete-remote-files="false">
        <int:poller fixed-rate="1000"/>
</int-sftp:inbound-channel-adapter>

    <int:channel id="requestChannel">
        <int:queue/>
    </int:channel>


    <bean id="dataSource" 
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="${db.driver}"/>
      <property name="url" value="${db.url}"/>
      <property name="username" value="${db.user}"/>
      <property name="password" value="${db.password}"/>
   </bean>


    <!-- Defining a datasource -->
<!--    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <description>This is JNDI based Data Source.</description>
        <property name="jndiName">
            <value>jdbc/BIZLOGDS</value>
        </property>
    </bean> -->

       <!-- Definition for JDBCTemplate bean -->
   <bean id="jdbcTemplate" 
      class="org.springframework.jdbc.core.JdbcTemplate">
      <property name="dataSource"  ref="dataSource" />    
   </bean>

    <bean id="TransactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

</beans>

堆栈跟踪:

org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler shutdown
    INFO: Shutting down ExecutorService 'myScheduler'
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sftpSessionFactory' defined in class path resource [app-config.xml]: Cannot resolve reference to bean 'defaultSftpSessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultSftpSessionFactory' defined in class path resource [app-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'sftp' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
        at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:646)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
        at com.canaldigital.tsi.bank.config.AppMain.main(AppMain.java:16)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultSftpSessionFactory' defined in class path resource [app-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'sftp' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
        ... 17 more
    Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'sftp' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
        at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:146)
        at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1362)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:214)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:186)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
        ... 23 more
    Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'sftp' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:215)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:78)
        at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:48)
        at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:84)
        at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:103)
        at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:94)
        at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:143)
        ... 29 more

请访问DefaultSftpSessionFactory

它有以下内容:

 setUser

    public void setUser(String user)

    The remote user to use. This is a mandatory property.

    Parameters:
        user - The user.
    See Also:
        JSch.getSession(String, String, int)