- 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.
推薦閱讀
- 復(fù)雜軟件設(shè)計(jì)之道:領(lǐng)域驅(qū)動(dòng)設(shè)計(jì)全面解析與實(shí)戰(zhàn)
- Java Web基礎(chǔ)與實(shí)例教程(第2版·微課版)
- Software Testing using Visual Studio 2012
- Web開發(fā)的貴族:ASP.NET 3.5+SQL Server 2008
- Learning ArcGIS Pro
- Python程序設(shè)計(jì)
- JS全書:JavaScript Web前端開發(fā)指南
- 算法訓(xùn)練營(yíng):提高篇(全彩版)
- Keras深度學(xué)習(xí)實(shí)戰(zhàn)
- Visual C#.NET Web應(yīng)用程序設(shè)計(jì)
- Python從入門到精通(第3版)
- Getting Started with Web Components
- 游戲設(shè)計(jì)的底層邏輯
- 少兒編程輕松學(xué)(全2冊(cè))
- Hands-On ROS for Robotics Programming