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

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.

主站蜘蛛池模板: 凤凰县| 宣城市| 东丰县| 开封市| 武鸣县| 三明市| 融水| 屯昌县| 抚州市| 关岭| 喀喇沁旗| 克拉玛依市| 澎湖县| 同心县| 滕州市| 宿迁市| 惠水县| 厦门市| 东兴市| 丹东市| 崇左市| 前郭尔| 巴彦淖尔市| 楚雄市| 藁城市| 宾川县| 平谷区| 汪清县| 黑河市| 铁力市| 临沂市| 天长市| 绩溪县| 大洼县| 襄汾县| 奉贤区| 宁晋县| 札达县| 江安县| 革吉县| 西城区|