Get Spring application context after running the service

Submitted by Jochus on Fri, 17/11/2017 - 13:35 | Posted in: Java


My goal was - for testing - to get a bean from the Spring AppliciationContext. The class of my bean is 'MyBean':

ConfigurableApplicationContext context = SpringApplication.run(Service.class, args);
MyBean myBean = context.getBean(MyBean.class);

Add new comment

The content of this field is kept private and will not be shown publicly.

Full HTML

  • Lines and paragraphs break automatically.
  • You can caption images (data-caption="Text"), but also videos, blockquotes, and so on.
  • Web page addresses and email addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <cpp>, <css>, <html5>, <java>, <php>, <sql>, <xml>. The supported tag styles are: <foo>, [foo].