我使用Spring-integration 4.1.1.RELEASE并拥有将消息有效负载中的文件上传到远程sFtp共享的代码。我正在使用像这样初始化的sFtpRemoteFileTemplate:
Expression remoteDirectoryExpression = new LiteralExpression("si.sftp.sample");
SpelExpressionParser parser = new SpelExpressionParser();
Expression fileNameExpression = parser.parseExpression("payload.name");
template = new SftpRemoteFileTemplate(sessionFactory);
template.setCharset("UTF-8");
template.setBeanFactory(beanFactory);
template.setAutoCreateDirectory(true);
template.setRemoteDirectoryExpression(remoteDirectoryExpression);
template.setFileNameExpression(fileNameExpression);
template.setTemporaryFileSuffix(".writing");
template.setUseTemporaryFileName(true);
但是,在运行代码时,此警告会出现在我的日志文件中 - 模板中的每个表达式都会出现一次:
WARN - o.s.i.e.ExpressionUtils: Creating EvaluationContext with no beanFactory
java.lang.RuntimeException: No beanfactory
at org.springframework.integration.expression.ExpressionUtils.createStandardEvaluationContext(ExpressionUtils.java:79) [spring-integration-core-4.1.1.RELEASE.jar:na]
at org.springframework.integration.util.AbstractExpressionEvaluator.getEvaluationContext(AbstractExpressionEvaluator.java:114) [spring-integration-core-4.1.1.RELEASE.jar:na]
at org.springframework.integration.util.AbstractExpressionEvaluator.getEvaluationContext(AbstractExpressionEvaluator.java:100) [spring-integration-core-4.1.1.RELEASE.jar:na]
at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:164) [spring-integration-core-4.1.1.RELEASE.jar:na]
at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:123) [spring-integration-core-4.1.1.RELEASE.jar:na]
at org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor.processMessage(ExpressionEvaluatingMessageProcessor.java:72) [spring-integration-core-4.1.1.RELEASE.jar:na]
为什么?我还没有设法摆脱它,我怀疑Bean Factory实例没有委托给RemoteFileTemplate里面的ExpressionEvaluatingMessageProcessor(调用类已经实现了BeanFactoryAware,我已经验证了beanFactory字段是否正确填充了)。我已经为它创建了一个测试用例,我已经成功地重现了它。
@Test
public void shouldUploadFile() throws Exception
{
Message<File> msg = MessageBuilder
.withPayload(Fixture.getFile())
.build();
final String remoteDir = template.send(msg);
org.junit.Assert.assertNotNull("remote file must exist", remoteDir);
logger.info("uploaded file: \'{}\'", remoteDir);
SftpTestUtils.cleanUp(template, Fixture.getFileName());
}
它不应该是ExpressionEvaluatingMessageProcessor的问题,因为这个测试用例在相同的上下文中没有警告地传递:
@Test
public void shouldTestProcessor()
{
SpelExpressionParser parser = new SpelExpressionParser();
Expression fileNameExpression = parser.parseExpression("payload.name");
ExpressionEvaluatingMessageProcessor<String> fileNameProcessor = new ExpressionEvaluatingMessageProcessor<String>(
fileNameExpression, String.class);
fileNameProcessor.setBeanFactory(beanFactory);
Message<File> message = MessageBuilder.withPayload(Fixture.getFile()).build();
String fileName = fileNameProcessor.processMessage(message);
org.junit.Assert.assertEquals("filename is not as expected", Fixture.getFileName(), fileName);
logger.info("generated fileName: \'{}\'", fileName);
}
任何线索?
答案 0 :(得分:3)
在Spring afterPropertiesSet()
之外构建RFT时,需要调用ApplicationContext
来完成RFT的初始化。
对于许多Spring Integration组件都是如此。
实施Lifecycle
(非RFT)的人可能还需要start()
。
答案 1 :(得分:-2)
您只需在日志中添加以下行
<logger name="org.springframework.integration.expression.ExpressionUtils">
<level value="ERROR"/>
<appender-ref ref="console" />
</logger>
然后你不会得到这个警告..我希望