So if our SpringBootRestApplication class is in package, then it won’t scan package. SpringBootApplication scanBasePackagesīy default SpringApplication scans the configuration class package and all it’s sub-pacakges. Import class SpringBootRestApplication " etc.īelow image shows an example invocation of the APIs exposed by our Spring Boot Application. Now we have to create a java class with main method, mark it with annotation and invoke n() method. We can delete WebContent directory or leave it as is, it won’t be used by our Spring Boot application. We will also have to add spring-boot-maven-plugin plugin, this plugin lets us run our simple java application as spring boot application. However, we will have to keep JAXB dependencies because we are running on Java 10 and we want to support XML request and responses too. Since it’s a REST web service, we only need spring-boot-starter-web dependency. The first step is to clean up pom.xml file and configure it for Spring Boot. You should check out the existing project from our GitHub Repository, in following sections we will make necessary changes to the project files.īelow image shows our final project structure. This will help in the quick testing of our application logic because we won’t have to manually build and deploy the project to the external Tomcat server. Here we will change the project to run as a Spring Boot Application and get rid of configuration files. We also had to manually add Spring MVC dependencies and manage their versions. We had to create web.xml and spring context file. In the last tutorial on Spring RestController, we created a Spring RESTful web service and deployed it on Tomcat. SpringBootApplication and SpringApplication Example This class is very helpful in launching Spring MVC or Spring REST application using Spring Boot. This class automatically creates the ApplicationContext from the classpath, scan the configuration classes and launch the application. Spring Boot SpringApplication class is used to bootstrap and launch a Spring application from a Java main method. It’s same as declaring a class with and annotations. Spring Boot annotation is used to mark a configuration class that declares one or more methods and also triggers auto-configuration and component scanning.
0 Comments
Leave a Reply. |