मैं एक ध्वनि ब्रोकर विषय से कनेक्ट करना चाहता हूं और किसी भी आने वाले एक्सएमएल संदेश के लिए सुनना चाहता हूं। मैंने नीचे कुछ ऐसा किया;स्प्रिंग-बूट @ मुख्य वर्ग में आउटपुट किया गया है
Application.java
@SpringBootApplication
@ComponentScan({"com.mainpack", "com.msgpack.jms"})
@EnableJms
public class Application extends SpringBootServletInitializer {
@Autowired
private JmsTopicListener jmsTopicListener;
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
try {
LogService.info(Application.class.getName(), "Starting Service...");
super.onStartup(servletContext);
jmsTopicListener.listenMessage();
LogService.info(Application.class.getName(), "Service Started");
} catch (Exception ex) {
LogService.error(this.getClass().getName(), ex);
}
}
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(Application.class, args);
LogService.info(Application.class.getName(), "Service Started...");
}
}
JmsTopicListener.java
@Component
public class JmsTopicListener {
@Autowired
private ApplicationProperties properties;
@Autowired
private MsgListener msgListener;
public void listenMessage() {
TopicConnectionFactory factory;
TopicConnection connection = null;
LogService.info(this.getClass().getName(), "Registering Broker Connection");
try {
factory = new progress.message.jclient.TopicConnectionFactory(properties.getBrokerURL());
connection = factory.createTopicConnection(properties.getUserName(), properties.getPass());
javax.jms.TopicSession subSession = (TopicSession) connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Topic topic = subSession.createTopic(properties.getTopicName());
MessageConsumer subscriber = subSession.createSubscriber(topic);
subscriber.setMessageListener(msgListener);
connection.start();
LogService.info(this.getClass().getName(), "Broker connected");
} catch (Exception ex) {
LogService.error(this.getClass().getName(), ex);
}
}
}
MsgListener.java
@Component
public class MsgListener implements MessageListener {
@Override
public void onMessage(Message msg) {
if (msg instanceof XMLMessage) {
try {
XMLMessage m = (XMLMessage) msg;
if (m.getText().contains("Applications")) {
LogService.info(this.getClass().getName(), "Recieved A Applications Message");
} else {
LogService.info(this.getClass().getName(), "Recieved Message Does not contain Applications Tag");
}
} catch (Exception ex) {
LogService.info(this.getClass().getName(), "Exception: " + ex.getMessage());
}
}
}
}
करते हैं, तो मैं इस कोड मैं Application.java
में लाइन jmsTopicListener.listenMessage()
पर nullPointer मिल चलाते हैं।
मैंने यहां क्या गलती की है? क्या कोई तरीका है जिससे मैं इसे सुधार सकता हूं (मेरा मतलब है कि कम कोड में काम किया जा सकता है)?
नोट: com.mainpack कक्षाएं Application.java
और ApplicationProp.java
com.msgpack.jms किया है लॉगर से JmsTopicListener.java
और MsgListner.java
त्रुटि:
ERROR [2015-07-14 14:34:52] [com.mainpack.Application] [localhost-startStop-1] - [Exception: ]java.lang.NullPointerException
at com.mainpack.Application.onStartup(Application.java:33)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:945)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1768)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
आप पूर्ण स्टैक ट्रेस यहाँ – kuhajeyan
@kbird मुद्रित कर सकते हैं: स्टैक ट्रेस जोड़ा गया। कृपया अद्यतन पोस्ट देखें। जब मैं टॉमकैट में सेवा शुरू करता हूं तो मुझे इसे लॉगर में मिलता है। तब कुछ भी नहीं होता है। सेवा आगे नहीं चलती है। – Raj
'@ SpringBootAplication' के रूप में '@ कॉन्फ़िगरेशन', '@ EnableAutoConfiguration' और' @ ComponentScan' के लिए सिर्फ एक शॉर्टकट है, यह पहले से ही आपकी समस्या हो सकती है। आप अपने एप्लिकेशन क्लास में '@ ऑटोवायर' संसाधन तक पहुंचने का प्रयास कर रहे हैं जो न तो '@ घटक', '@ सेवा' है ... जो वसंत द्वारा प्रबंधन के लिए अर्हता प्राप्त करेगा और निर्भरताओं को इंजेक्ट करेगा। आपको --debug मोड में चलकर दोबारा जांच करनी चाहिए। –