Rey*_*ldo 5 java messaging spring sftp spring-integration
我正在使用 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);
Run Code Online (Sandbox Code Playgroud)
但是,在运行代码时,此警告出现在我的日志文件中 - 对于模板中的每个表达式一次:
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]
Run Code Online (Sandbox Code Playgroud)
这是为什么?我还没有设法摆脱它,我怀疑 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());
}
Run Code Online (Sandbox Code Playgroud)
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);
}
Run Code Online (Sandbox Code Playgroud)
有什么线索吗?
afterPropertiesSet()在 Spring 外部构建 RFT 时,您需要调用来完成 RFT 的初始化ApplicationContext。
对于许多 Spring Integration 组件来说都是如此。
那些实施Lifecycle(不是 RFT)的人可能也需要进行start()编辑。
| 归档时间: |
|
| 查看次数: |
3579 次 |
| 最近记录: |