- Docker and Kubernetes for Java Developers
- Jaroslaw Krochmalski
- 228字
- 2021-07-02 18:44:58
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.
推薦閱讀
- Linux C/C++服務器開發實踐
- 劍指JVM:虛擬機實踐與性能調優
- Magento 2 Theme Design(Second Edition)
- C程序設計案例教程
- 微信小程序項目開發實戰
- Unity 5 for Android Essentials
- 大數據分析與應用實戰:統計機器學習之數據導向編程
- Mastering Business Intelligence with MicroStrategy
- Android移動開發案例教程:基于Android Studio開發環境
- Visualforce Developer’s guide
- 智能手機故障檢測與維修從入門到精通
- MongoDB Administrator’s Guide
- Qt 5.12實戰
- Practical Linux Security Cookbook
- C++程序設計習題與實驗指導