Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Get application context in @SpringUI class
So thats my spring boot:
@ImportResource("classpath:spring.xml")
@SpringBootApplication
public class AppApplication {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(AppApplication.class, args);
}
}
Right now to acces beans I'm using this code:
@SuppressWarnings("serial")
@SpringUI
public class MyVaadinUI extends UI {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
Anyway creating another Context object is not good practise. How can I acces "ctx" from AppApplication in UI ?
Inject Application context markin your field with @Autowired annotation (or use constructor injection) or make yout UI class implement ApplicationContextAware interface
@SpringUI
public class MyVaadinUI extends UI {
@Autowired
ApplicationContext applicationContext;
}
or
@SpringUI
public class MyVaadinUI extends UI implements ApplicationContextAware {
ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext appCtx) {
this.applicationContext = appCtx;
}
}
Sorry that i didn't mention it. I tried with @Autowired but when I try to take a bean from @Autowired context all I receive is NULL. In class AppApplication all beans are fine. I tried right now method with implement ApplicationContextAware interface, same situation getBean() return NULL.
ApplicationContext @Autowired works well for me, also importing bean definitions from xml file with @ImportResource.
Could you post some more code?
Everything is fine. Problem was not there. Thanks that helped me a lot.