官术网_书友最值得收藏!

Application entry point

Our application entry point will be named BookStoreApplication and will be BookstoreApplication.java:

package pl.finsys.example; 
 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
 
@SpringBootApplication 
public class BookstoreApplication { 
 
    public static void main(final String[] args) { 
        SpringApplication.run(BookstoreApplication.class, args); 
    } 
} 

That's it. The whole nine lines of code, not counting blank lines. It could not be more concise. The @SpringBootApplication is a kind of shortcut annotation, which is very convenient. It replaces all of the following annotations:

  • @Configuration: A class marked with this annotation becomes a source of bean definitions for the application context
  • @EnableAutoConfiguration: This annotation makes Spring Boot add beans based on classpath settings, other beans, and various property settings
  • @EnableWebMvc: Normally you would add this one for a Spring MVC application, but Spring Boot adds it automatically when it sees spring-webmvc on the classpath. This marks the application as a web application, which in turn will activate key behaviors such as setting up a DispatcherServlet
  • @ComponentScan: Tells Spring to look for other components, configurations, and services, allowing it to find the controllers

So far so good. We need some models for our service. We are going to save some entities in the database; this is where the spring-boot-starter-data-jpa starter will come in handy. We will be able to use JPA (implemented with Hibernate) and javax.transaction-api without even declaring it explicitly. We need an entity model for our bookstore.

主站蜘蛛池模板: 汉中市| 漳平市| 黑河市| 龙岩市| 乐至县| 双辽市| 神池县| 航空| 大石桥市| 裕民县| 佛坪县| 安溪县| 山东| 育儿| 蕲春县| 林周县| 阿拉善左旗| 永济市| 湟中县| 任丘市| 靖江市| 项城市| 虹口区| 轮台县| 得荣县| 兴业县| 深州市| 遵化市| 江安县| 额尔古纳市| 永仁县| 遂昌县| 墨竹工卡县| 开封市| 康乐县| 淮阳县| 刚察县| 黑河市| 阿拉善左旗| 广南县| 马公市|