Reputation: 2979
I was trying to understand how to build "basic" web app with spring boot. I found different articles online to do it in various different ways:
@SpringBootApplication
extends SpringBootServletInitializer
SpringApplication.run()
in its main()
@Controller
and JSP pagesextends SpringBootServletInitializer
implements CommandLineRunner
My questions:
extends SpringBootServletInitializer
in article 1 unnecessary?CommandLineRunner
is required to build non web apps. Then how example in article 3 works?Upvotes: 0
Views: 104
Reputation: 159086
Are approaches correct?
Yes.
What is difference between them?
#1 extends SpringBootServletInitializer
so the web application can also be deployed as a .war file into a standalone servlet container, instead of running it from the command-line using the embedded servlet container.
#2 didn't need that optional feature for the demo.
#3 uses CommandLineRunner
to seed test data needed by its demo.
extends SpringBootServletInitializer
in article 1 unnecessary?
Yes. Only needed if you want to be able to deploy as .war file.
I read
CommandLineRunner
is required to build non web apps. Then how example in article 3 works?
It might be required for non web app, but that doesn't mean it's invalid for a web app.
Non web apps (may) need it as the entry point for running the main non web app logic.
Web apps don't need it, unless they need extra initialization logic, because the embedded servlet container is automatically started by SpringApplication.run()
.
Upvotes: 3