title: NullPointerException : Cannot send from MessageListener to client via websocket with Spring boot
body: <p>I am trying to send message to topic <code>/topic/room</code>, after subscribed message from Redis.
  My code is following.</p>
  
  <pre><code>@Component
  public class RedisSubscriber implements MessageListener {
  
      static private Logger log = Logger.getLogger(RedisSubscriber.class.getName());
  
      @Autowired
      private SimpMessagingTemplate template;
  
      @Override
      public void onMessage(final Message message, final byte[] pattern) {
  
          log.info("template: " + template);
          template.convertAndSend("/topic/room", message);
          log.info("Message send: " + message.toString());
      }
  }
  </code></pre>
  
  <p>Result is following.
  I don't know why <code>SimpMessagingTemplate</code> object is null.
  It seems SimpMessagingTemplate is not <code>@Autowired</code>.
  Do I need to create other template or not?
  Please advise to me.</p>
  
  <p>Got following exception</p>
  
  <pre><code>2017-07-12 19:53:24.920  INFO 8724 --- [edisContainer-2] j.c.t.l.delivery.redis.RedisSubscriber   : template: null
  2017-07-12 19:53:24.939 ERROR 8724 --- [edisContainer-2] o.s.d.r.l.a.MessageListenerAdapter       : Listener execution failed
  
  java.lang.NullPointerException: null
      at XXXX.redis.RedisSubscriber.onMessage(RedisSubscriber.java:27) ~[classes/:na]
      at org.springframework.data.redis.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:299) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
      at org.springframework.data.redis.listener.RedisMessageListenerContainer.executeListener(RedisMessageListenerContainer.java:249) [spring-data-redis-1.8.4.RELEASE.jar:na]
      at org.springframework.data.redis.listener.RedisMessageListenerContainer.processMessage(RedisMessageListenerContainer.java:239) [spring-data-redis-1.8.4.RELEASE.jar:na]
      at org.springframework.data.redis.listener.RedisMessageListenerContainer$1.run(RedisMessageListenerContainer.java:967) [spring-data-redis-1.8.4.RELEASE.jar:na]
      at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
  </code></pre>
  
  <p>Addtional infomation is following.
  This is how I obtain <code>RedisSubscriber</code> to register it with <code>MessageListenerAdapter</code>.</p>
  
  <pre><code>@Configuration
  @EnableScheduling
  public class AppConfig {
  
      @Bean
      JedisConnectionFactory jedisConnectionFactory() {
          return new JedisConnectionFactory();
      }
  
      @Bean
      RedisTemplate&lt;String, Object&gt; redisTemplate() {
          final RedisTemplate&lt;String, Object&gt; template = new RedisTemplate&lt;String, Object&gt;();
          template.setConnectionFactory(jedisConnectionFactory());
          template.setKeySerializer(new StringRedisSerializer());
          template.setHashValueSerializer(new GenericToStringSerializer&lt;Object&gt;(Object.class));
          template.setValueSerializer(new GenericToStringSerializer&lt;Object&gt;(Object.class));
          return template;
      }
  
      @Bean
      MessageListenerAdapter messageListener() {
          return new MessageListenerAdapter(new RedisSubscriber());
      }
  
      @Bean
      RedisMessageListenerContainer redisContainer() {
          final RedisMessageListenerContainer container = new RedisMessageListenerContainer();
  
          container.setConnectionFactory(jedisConnectionFactory());
          container.addMessageListener(messageListener(), topic());
  
          return container;
      }
  
      @Bean
      RedisPublisher redisPublisher() {
          return new RedisPublisher(redisTemplate(), topic());
      }
  
      @Bean
      ChannelTopic topic() {
          return new ChannelTopic("topic");
      }
  }
  </code></pre>