Spring Resource Loader SpEL错误 - EL1004E:(pos 24)

时间:2015-09-17 22:04:52

标签: java spring amazon-s3 spring-batch spring-el

我正尝试使用以下方法从S3存储桶访问数据。 创建了一个SpringInjection类

public class SpringResourceInjection {

    @Inject
    public AmazonS3 s3client2;

    @Autowired
    public ResourceLoader resourceLoader;

    public Resource s3Resource;


    public Resource getS3Resource() {
        return s3Resource;
    }

    public void setS3Resource(Resource s3Resource) {
        this.s3Resource = s3Resource;
    }
}

并在我的应用程序上下文中自动装配bean

<bean id="springResourceInjection" class="com.xx..SpringResourceInjection" scope="step">
    <property name="s3Resource" value="s3:// + ${awsBucketName} + / + #{stepExecutionContext['fileResource']}"/>
</bean>

并通过sPEL为资源变量

调用getResource方法
<bean id="itemreader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<property name="resource" value="#{springResourceInjection.getS3Resource()}"/>

我得到错误,说找不到com.sun.proxy类型的方法。$ Proxy18我的配置有问题。请帮忙。

错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.itemreader' defined in class path resource [spring-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: EL1004E:(pos 24): Method call: Method getS3Resource() cannot be found on com.sun.proxy.$Proxy18 type
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:548)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:341)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:110)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:336)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:187)
at com.sun.proxy.$Proxy19.open(Unknown Source)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96)
at org.springframework.batch.core.step.item.ChunkMonitor.open(ChunkMonitor.java:114)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler$1.call(TaskExecutorPartitionHandler.java:139)
at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler$1.call(TaskExecutorPartitionHandler.java:136)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

引起:org.springframework.beans.factory.BeanExpressionException:表达式解析失败;嵌套异常是org.springframework.expression.spel.SpelEvaluationException:EL1004E:(pos 24):方法调用:在com.sun.proxy上找不到方法getS3Resource()。$ Proxy18类型     在org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:146)

1 个答案:

答案 0 :(得分:0)

快速而肮脏的尝试尝试:#{springResourceInjection.S3Resource}

使用标准java代理进行代理的Scoped bean不会暴露具体的类方法。
你有两个选择:

  1. 使SpringResourceInjection成为一个界面并使用S3Resource访问者
  2. 使用CGLIB创建代理
  3. 第一个解决方案非常简单,第二个解决方案需要更多工作(你可以在SO上找到很多信息)。

    总结一下:为什么要混用xml和java配置?通常是个坏主意;做出选择并继续。