What is Springboot?
Spring boot is nothing but opinionated version of Spring framework.
Note: Spring boot uses Java technology in the Background as a result Java or JDK must be in your System.
Spring boot starter project?????
What is Spring boot parent starter Project??
Q. what is spring boot application??
A Spring boot application is standalone application and we need not to deploy it anywhere, because it already comes with apache tomacat server.
Steps to create Spring boot Application??
1. use Annotation @SpringBootApplication and this is the starting point of application
2. To run application we need to use SpringApplication.run(Application.class);
Ref: https://medium.com/@cancerian0684/run-method-on-application-startup-in-spring-boot-37aa5e82c948
Another Way
You can use an ApplicationListener
public class MyApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
public void onApplicationEvent(final ContextRefreshedEvent event) {
ApplicationContext ctx = event.getApplicationContext();
(new Thread() {
public void run() {
// do stuff
}
}).start();
}
}
Just register that as a Spring bean. As suggested in the comments, you can execute the code on another thread.
Noe: After run this application following things happens:
1. loads the default page.
2. Starts the boo app.
3. Perform a class path scan.
4. Starts local tomcat.
For controller class use @Controller anotation
use @Requestmapping for url pattern.
Note: Spring boot uses embedded tomcat server , it happens due to tomcat embedded dependency jar.
Note: By default our Spring Application doesn't support rendering of JSP page.Hence we need to add dependency for tomcat embedded jasper
In application.properties can be used for following ways if jsp page is not in default folder package :
The Solution
I found the answer via trial-and-error, which turned out rather annoying. I hope someone can correct me if this conclusion is wrong, but it appears that Spring Boot does not like the string WEB-INF
. I renamed the WEB-INF
directory to view
and changed the application.properties
to the following and the view loaded successfully.
spring.mvc.view.prefix=/view/
spring.mvc.view.suffix=.jsp
No comments:
Post a Comment