Issue
Whole magic here what it crashes only on linux\server\laptop machine and perfectly working(autowiring) on mac. I have
@EnableWebSocketMessageBroker
@Configuration
public class WebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer {
@Autowired
private A a;
@Autowired
private B b;
@Autowired
private C c;
@Autowired
private D d;
....
}
if one of these classes (for example C) have
@Autowired
private SimpMessagingTemplate simpMessagingTemplate;
then C becames null on WebSocketConfiguration and all following classes also becames as null (D class in current example also. So order important here)
Interesting what on Mac laptops it works perfectly but on server and my linux laptop I have troubles.
Also within A,B,C,D classes have references to each other (circular dependencies autowiring) but as I understand Spring have to resolve it very easy.
If I remove @Autowire from SimpMessagingTemplate all classes load perfectly and works.
What might be a problem here?
Solution
Found solution after 3 days of research.
Ive moved SimpMessagingTemplate to configuration class and use PostConstruct to set it to other beans.
Looks like here exist some order in beans initializations.
Answered By - 0dd_b1t
Answer Checked By - Mildred Charles (JavaFixing Admin)