似乎 BeanPostProcessor 接口实现对@ServiceActivator 产生了影响。将 BeanPostProcessor 与 @ServiceActivator 一起使用的方式应该是什么。谢谢。
这里有完整的日志logs
以下是用于 SFTP 的 Java Config -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | package com.ftp.example; import java.io.File; import org.slf4j.Logger; import com.jcraft.jsch.ChannelSftp.LsEntry; @Configuration private Logger LOG = LoggerFactory.getLogger(DependencySpringConfiguration.class); @Value("${project.name}") @Value("${${project.name}.ftp.server}") @Value("${${project.name}.ftp.port}") @Value("${${project.name}.ftp.username}") @Value("${${project.name}.ftp.password}") @Value("${${project.name}.ftp.remote.directory}") @Bean @Bean /* @Bean @Bean @Bean @Bean @Override }); @MessagingGateway } |
我们在做 SFTP 时像这样调用网关对象
主类
1 2 3 4 5 6 7 8 9 10 11 12 13 | public class FtpExample { public static String[] ARGS; public static void main(String[] args) throws Exception { ProcessStarter processStarter = ctx.getBean(ProcessStarter.class); |
其他类 -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public class ProcessStarter { @Inject private FTPOutService ftpOutService; public void startService() { public class FTPOutService { @Inject public void ftpToBbg() { log.info("Starting FTP out process..."); } |
除非我没有在上面定义的 Java Config -
中添加以下 bean 声明,否则上面的代码工作正常
1 2 3 | public LogInjector logInjector() { return new LogInjector(); } |
上面的 bean 定义有以下实现 -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | public class LogInjector implements BeanPostProcessor { @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { return bean; } @Override @Retention(RetentionPolicy.RUNTIME) |
一旦在 Java Config 中添加任何 BeanPostProcessor 实现,它就会产生问题并且应用程序无法看到 toSftpChannel -
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named 'toSftpChannel' available at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:685)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1199)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at
org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveDestination(BeanFactoryChannelResolver.java:88)
at
org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveDestination(BeanFactoryChannelResolver.java:45)
at
org.springframework.integration.gateway.MessagingGatewaySupport.getRequestChannel(MessagingGatewaySupport.java:327)
at
org.springframework.integration.gateway.MessagingGatewaySupport.send(MessagingGatewaySupport.java:368)
at
org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:477)
at
org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:429)
at
org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:420)
at
org.springframework.integration.gateway.GatewayCompletableFutureProxyFactoryBean.invoke(GatewayCompletableFutureProxyFactoryBean.java:65)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy57.sendToSftp(Unknown Source)
相关讨论
看看你有什么:
1 2 3 4 | @Bean public LogInjector logInjector() { return new LogInjector(); } |
如果您将
You may declare
@Bean methods as static, allowing for them to be called without creating their containing configuration class as an instance. This makes particular sense when defining post-processor beans, e.g. of typeBeanFactoryPostProcessor orBeanPostProcessor , since such beans will get initialized early in the container lifecycle and should avoid triggering other parts of the configuration at that point.