Reputation: 1297
Its possible to create the context these ways:
But I dont wanna use xml configurtions in my projects at all. I like annotations. So do I still need to select 1)...3) or just use annotations like
Or even I gonna use SpringBoot, there is @SpringBootApplication
a is a convenience annotation that adds all of the following:
@Configuration tags the class as a source of bean definitions for the application context. @EnableAutoConfiguration tells Spring Boot to start adding beans based on classpath settings, other beans, and various property settings. Normally you would add @EnableWebMvc for a Spring MVC app, but Spring Boot adds it automatically when it sees spring-webmvc on the classpath. This flags the application as a web application and activates key behaviors such as setting up a DispatcherServlet.
@ComponentScan tells Spring to look for other components, configurations, and services in the package, allowing it to find the controllers.
So back to my question: Do I still need the *********ApplicationContext stuff in my projects or not?
Upvotes: 0
Views: 447
Reputation: 339
If you use Spring Boot you should create the context like this:
@SpringBootApplication
public class TestApplication {
public static void main(final String[] args) {
final SpringApplication app = new SpringApplication(TestApplication.class);
app.run(args);
}
}
Method run
here create the context for your application.
Upvotes: 1