how-to-access-in-memory-h2-database-of-one-spring-boot-application-from-another

You need to add a server to start H2Database

@SpringBootApplication
@MapperScan("com.qctc.activiti.mapper")
public class ActivitiApplication {

    public static void main(String[] args) {
        SpringApplication.run(ActivitiApplication.class, args);
    }

    @Bean(initMethod = "start", destroyMethod = "stop")
    public Server h2Server(a) throws SQLException {
        return Server.createTcpServer("-tcp"."-tcpAllowOthers"."-tcpPort"."9092"); }}Copy the code
server:
  port: 9090
spring:
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:./db/H2/testdb
    username: root
    password: root
  h2:
    console:
      enabled: true # Enable the Web Console function
      path: /h2
      settings:
        web-allow-others: true
Copy the code

http://localhost:9090/h2 direct access, you can log on

Database connection using IDEAYou can see the table now