Spring Boot H2 简明教程
Spring Boot & H2 - Environment Setup
本章将指导你如何准备一个开发环境来开始你使用 Spring Framework 的工作。它还将教你如何在设置 Spring Framework 之前在你的机器上设置 JDK、Tomcat 和 Eclipse −
This chapter will guide you on how to prepare a development environment to start your work with Spring Framework. It will also teach you how to set up JDK, Tomcat and Eclipse on your machine before you set up Spring Framework −
Step 1 - Setup Java Development Kit (JDK)
Java SE 可免费下载。若要下载 click here,请下载与你的操作系统兼容的版本。
Java SE is available for download for free. To download click here, please download a version compatible with your operating system.
按照说明下载 Java,并运行 .exe 在你的计算机上安装 Java。在计算机上安装 Java 后,你需要设置环境变量来指向正确的安装目录。
Follow the instructions to download Java, and run the .exe to install Java on your machine. Once you have installed Java on your machine, you would need to set environment variables to point to correct installation directories.
Setting Up the Path for Windows 2000/XP
假设你已将 Java 安装在 c:\Program Files\java\jdk 目录中 −
Assuming you have installed Java in c:\Program Files\java\jdk directory −
-
Right-click on 'My Computer' and select 'Properties'.
-
Click on the 'Environment variables' button under the 'Advanced' tab.
-
Now, edit the 'Path' variable and add the path to the Java executable directory at the end of it. For example, if the path is currently set to C:\Windows\System32, then edit it the following way
C:\Windows\System32;c:\Program Files\java\jdk\bin
Setting Up the Path for Windows 95/98/ME
假设你已将 Java 安装在 c:\Program Files\java\jdk 目录中 −
Assuming you have installed Java in c:\Program Files\java\jdk directory −
-
Edit the 'C:\autoexec.bat' file and add the following line at the end −
SET PATH=%PATH%;C:\Program Files\java\jdk\bin
Setting Up the Path for Linux, UNIX, Solaris, FreeBSD
环境变量 PATH 应设置为指向已安装 Java 二进制文件的位置。如果你在这方面遇到问题,请参阅 shell 文档。
Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation if you have trouble doing this.
例如,如果你使用 bash 作为你的 shell,那么你将在 .bashrc 的末尾添加以下行 −
For example, if you use bash as your shell, then you would add the following line at the end of your .bashrc −
export PATH=/path/to/java:$PATH'
或者,如果你使用诸如 Borland JBuilder、Eclipse、IntelliJ IDEA 或 Sun ONE Studio 这样的集成开发环境 (IDE),则必须编译并运行一个简单程序来确认 IDE 知道你在何处安装了 Java。否则,你必须按照 IDE 文档中给出的内容执行正确的设置。
Alternatively, if you use an Integrated Development Environment (IDE) like Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio, you will have to compile and run a simple program to confirm that the IDE knows where you have installed Java. Otherwise, you will have to carry out a proper setup as given in the document of the IDE.
Step 2 - Setup Eclipse IDE
本教程中的所有示例都是使用 Eclipse IDE 编写的。因此,我们建议你应该在你机器上安装 Eclipse 的最新版本。
All the examples in this tutorial have been written using Eclipse IDE. So we would suggest you should have the latest version of Eclipse installed on your machine.
要安装 Eclipse IDE,请从 www.eclipse.org/downloads 下载最新的 Eclipse 二进制文件。下载安装文件后,将二进制分发包解压到方便的位置。例如,在 Windows 上的 C:\eclipse 中,或 Linux/Unix 上的 /usr/local/eclipse 中,最后相应地设置 PATH 变量。
To install Eclipse IDE, download the latest Eclipse binaries from www.eclipse.org/downloads. Once you download the installation, unpack the binary distribution into a convenient location. For example, in C:\eclipse on Windows, or /usr/local/eclipse on Linux/Unix and finally set PATH variable appropriately.
可以通过在 Windows 机器上执行以下命令启动 Eclipse,或者你只需双击 eclipse.exe
Eclipse can be started by executing the following commands on Windows machine, or you can simply double-click on eclipse.exe
%C:\eclipse\eclipse.exe
可以通过在 Unix(Solaris、Linux 等)机器上执行以下命令启动 Eclipse −
Eclipse can be started by executing the following commands on Unix (Solaris, Linux, etc.) machine −
$/usr/local/eclipse/eclipse
Step 3 - Setup m2eclipse
M2Eclipse 是一个 Eclipse 插件,它对于将 Apache Maven 集成到 Eclipse IDE 中非常有用。我们在本教程中使用 maven 来构建 spring boot 项目,并使用 m2eclipse 在 eclipse 内运行示例。
M2Eclipse is eclipse plugin which is very useful integration for Apache Maven into the Eclipse IDE. We are using maven in this tutorial to build spring boot project and examples are run within eclipse using m2eclipse.
使用 Eclipse IDE 中的 Install New Software 对话框安装最新的 M2Eclipse 版本,并将其指向这个 p2 存储库: https://download.eclipse.org/technology/m2e/releases/latest/
Install the latest M2Eclipse release by using the Install New Software dialog in Eclipse IDE, and point it to this p2 repository: https://download.eclipse.org/technology/m2e/releases/latest/
Step 4 - Setup Spring Boot Project
现在,如果一切正常,则可以继续设置 Spring Boot。以下是下载和在机器上安装 Spring Boot 项目的简单步骤。
Now if everything is fine, then you can proceed to set up your Spring Boot. Following are the simple steps to download and install the Spring Boot Project on your machine.
-
Go to spring Initializr link to create a spring boot project, https://start.spring.io/.
-
Select project as Maven Project.
-
Select language as Java.
-
Select Spring Boot version as 2.5.3.
-
Set Project Metadata - Group as com.tutorialspoint, Artifact as springboot-h2, name as springboot-h2, Description as Demo project for Spring Boot and H2 Database and package name as com.tutorialspoint.springboot-h2.
-
Select packaging as Jar.
-
Select java as 11.
-
Add dependencies as Spring Web, Spring Data JPA, H2 Database and Spring Boot DevTools.
现在点击生成按钮来生成项目结构。
Now click on GENERATE Button to generate the project structure.
一旦基于 maven 的 Spring Boot 项目下载完成,然后将 maven 项目导入 eclipse,其余操作由 eclipse 处理。它将下载 maven 依赖关系,并构建项目以使之可以进行进一步的开发。
Once the maven based spring boot project is downloaded, then import the maven project into eclipse and rest eclipse will handle. It will download the maven dependencies and build the project to make it ready for further development.
Step 5 - POSTMAN for REST APIs Testing
POSTMAN 是一款用来测试基于 REST 的 API 的有用工具。要安装 POSTMAN,可从 www.postman.com/downloads/ 下载最新的 POSTMAN 二进制文件。下载完可安装文件后,按照说明进行安装并使用。
POSTMAN is a useful tool to test REST Based APIs. To install POSTMAN, download the latest POSTMAN binaries from www.postman.com/downloads/. Once you download the installable, follow the instructions to install and use it.