Spring Boot H2 简明教程
Spring Boot & H2 - Console
与上一章 Application Setup 一样,我们在 Spring Boot 项目中创建了所需文件。现在让我们来更新位于 src/main/resources 和 pom.xml 中的 application.properties,以使用 maven-resources-plugin 的不同版本。
As in previous chapter Application Setup, we’ve created the required files in spring boot project. Now let’s update the application.properties lying in src/main/resources and pom.xml to use a different version of maven-resources-plugin.
application.properties
spring.datasource.url=jdbc:h2:mem:testdb
pom.xml
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</build>
...
Run the application
在 Eclipse 中,按照在 Application Setup 准备期间准备 Employee Application 配置。
In eclipse, run the Employee Application configuration as prepared during Application Setup
Eclipse 控制台将显示类似的输出。
Eclipse console will show the similar output.
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.tutorialspoint:sprint-boot-h2 >------------------
[INFO] Building sprint-boot-h2 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
...
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.2)
...
2021-07-24 20:51:11.347 INFO 9760 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer
: Tomcat initialized with port(s): 8080 (http)
...
2021-07-24 20:51:11.840 INFO 9760 --- [ restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration
: H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:testdb'
...
2021-07-24 20:51:14.805 INFO 9760 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer
: Tomcat started on port(s): 8080 (http) with context path ''
2021-07-24 20:51:14.823 INFO 9760 --- [ restartedMain] c.t.s.SprintBootH2Application
: Started SprintBootH2Application in 7.353 seconds (JVM running for 8.397)
服务器启动并运行后,在浏览器中打开 localhost:8080/h2-console ,然后点击“测试连接”以验证数据库连接。
Once server is up and running, open localhost:8080/h2-console in a browser and click on Test Connection to verify the database connection.
点击“连接”按钮,H2 数据库窗口将如以下所示出现 -
Click on Connect button and H2 database window will appear as shown below −