我正在尝试实现spring-boot-integration-smpp,但出现空指针异常。
integration-context.xml
<!--smpp integration-->
<int-smpp:outbound-gateway
id="smppIntegrationOutboundGateway"
request-channel="toSMPPChannel"
source-address="Indosat"
smpp-session-ref="smppSession"
reply-channel="fromSMPPChannel"/>
<int:service-activator ref="printService" method="print" input-channel="fromSMPPChannel">
<int:poller fixed-delay="1"/>
</int:service-activator>
<int:gateway id="smsGateway" service-interface="com.omexit.niger.smsworker.service.SMSGateway" default-request-channel="toSMPPChannel"/>
<!-- connect to the local broker using the default user name and password -->
<bean id="rabbitConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<constructor-arg value="${spring.rabbitmq.host}"/>
<constructor-arg value="${spring.rabbitmq.port}"/>
<property name="username" value="${spring.rabbitmq.username}"/>
<property name="password" value="${spring.rabbitmq.password}"/>
</bean>
<bean id="smppSession" class="org.springframework.integration.smpp.session.SmppSessionFactoryBean">
<property name="host" value="xxxx"/>
<property name="port" value="xx"/>
<property name="systemId" value="LBS1"/>
<property name="password" value="Bsl04n1"/>
<property name="systemType" value="TCP"/>
<property name="addrTon" value="INTERNATIONAL"/>
<property name="addrNpi" value="ISDN"/>
<property name="autoStartup" value="true"/>
</bean>
发送消息
System.err.println(strMessage);
Message<String> message = MessageBuilder.withPayload(strMessage)
.setHeader(SmppConstants.SRC_ADDR, "xyz")
.setHeader(SmppConstants.DST_ADDR, "6285781029162")
.setHeader(SmppConstants.REGISTERED_DELIVERY_MODE, SMSCDeliveryReceipt.SUCCESS)
.build();
String res = (String) smsGateway.send(message).getPayload();
System.err.println("Res: " +res);
例外:
2018-11-27 14:56:21.414 ERROR [-,,,] 24620 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.smpp.outbound.SmppOutboundGateway#0': Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.mode.indosat.smsworker.SmsWorkerApplication.main(SmsWorkerApplication.java:31) [classes/:na]
Caused by: java.lang.NullPointerException: null
at org.springframework.integration.smpp.session.SmppSessionFactoryBean$AutoReconnectLifecycle.scheduleReconnect(SmppSessionFactoryBean.java:548) ~[spring-integration-smpp-1.0.0.RELEASE.jar:na]
at org.springframework.integration.smpp.session.SmppSessionFactoryBean$AutoReconnectLifecycle.start(SmppSessionFactoryBean.java:487) ~[spring-integration-smpp-1.0.0.RELEASE.jar:na]
at org.springframework.integration.smpp.session.ExtendedSmppSessionAdaptingDelegate.start(ExtendedSmppSessionAdaptingDelegate.java:78) ~[spring-integration-smpp-1.0.0.RELEASE.jar:na]
at org.springframework.integration.smpp.outbound.SmppOutboundGateway.doInit(SmppOutboundGateway.java:62) ~[spring-integration-smpp-1.0.0.RELEASE.jar:na]
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.onInit(AbstractReplyProducingMessageHandler.java:94) ~[spring-integration-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.integration.context.IntegrationObjectSupport.afterPropertiesSet(IntegrationObjectSupport.java:178) ~[spring-integration-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
... 16 common frames omitted
答案 0 :(得分:0)
看起来像SmppOutboundGateway
中的错误:我们无法从session
这么早开始onInit()
。请针对https://github.com/spring-projects/spring-integration-extensions项目提出问题。
与此同时,您可以在reconnectingExecutor
上插入SmppSessionFactoryBean
属性:
<bean id="smppSession" class="org.springframework.integration.smpp.session.SmppSessionFactoryBean">
<property name="host" value="xxxx"/>
<property name="port" value="xx"/>
<property name="systemId" value="LBS1"/>
<property name="password" value="Bsl04n1"/>
<property name="systemType" value="TCP"/>
<property name="addrTon" value="INTERNATIONAL"/>
<property name="addrNpi" value="ISDN"/>
<property name="autoStartup" value="true"/>
<property name="reconnectingExecutor" ref="reconnectingExecutorService"/>
</bean>