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

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.

主站蜘蛛池模板: 鲁山县| 察雅县| 广河县| 新邵县| 铜川市| 石泉县| 惠水县| 兰州市| 叙永县| 克山县| 义乌市| 齐河县| 焦作市| 长泰县| 莆田市| 鄂尔多斯市| 沅陵县| 都安| 台中市| 老河口市| 肃宁县| 湘潭县| 克拉玛依市| 普定县| 汤原县| 大悟县| 松桃| 阜宁县| 新丰县| 清涧县| 宜君县| 黔西县| 东乌珠穆沁旗| 清水县| 客服| 政和县| 和林格尔县| 乐业县| 剑阁县| 华亭县| 赤水市|