BAEL-1980 Access an in-memory h2 db from 2 Spring Boot applications (#5230)
* Added Spring-Boot-H2 project * Optimized imports and formatted code * Code Formatting changes * Renamed the client applicaiton * Removed Name from pom.xml * formatting changes - applied formatting style * added souts * Update SpringBootApp.java * Update ClientSpringBootApp.java * Fixed Formatting issues * Fixed formatting and spelling mistakes * added H2 shared db example * a * patch * test * Revert "Fixed formatting and spelling mistakes" This reverts commit ed56ededec903e85c2d9f2b55e7730682455d5f5. * Revert "test" This reverts commit 4a7133dbd1d181cc304348f63998924a9db5acfe. * Revert "patch" This reverts commit 404b9ebe74aef4faa2ad62d9867652b62a5445b8. * Revert "a" This reverts commit af77f841114e19b0a0eafb15530dbaaaf34b5493. * Revert "added H2 shared db example" This reverts commit e16918cae3813fe20172c7e90e27bbec34b5fb5f. * Updated to have client and server in same directory * Deleted old files * removed unwanted directory * formating * removed unwanted module * commentted removed module * Revert "commentted removed module" This reverts commit 211ff1441f6bde920d7af3f8cd52c2a682ba3967. * Revert "removed unwanted module" This reverts commit 657f9ee45e02269bcfdbf380b9a74ff2370857fc. * fixed pom.xml issue * typo fixed * fixed multiple main class issue
This commit is contained in:
parent
80aabf2a23
commit
1dea2b8cbd
4
pom.xml
4
pom.xml
@ -675,7 +675,7 @@
|
|||||||
<!-- <module>rule-engines/rulebook</module> --><!-- Wrong Parent -->
|
<!-- <module>rule-engines/rulebook</module> --><!-- Wrong Parent -->
|
||||||
<module>spring-boot-custom-starter/greeter</module>
|
<module>spring-boot-custom-starter/greeter</module>
|
||||||
<module>spring-boot-h2/spring-boot-h2-database</module>
|
<module>spring-boot-h2/spring-boot-h2-database</module>
|
||||||
<module>spring-boot-h2/spring-boot-h2-remote-app</module>
|
<!--module>spring-boot-h2/spring-boot-h2-remote-app</module-->
|
||||||
<!-- <module>guest\webservices\rest-client</module> --><!-- guest post on different site -->
|
<!-- <module>guest\webservices\rest-client</module> --><!-- guest post on different site -->
|
||||||
<!-- <module>guest\webservices\rest-server</module> --><!-- PMD voilation -->
|
<!-- <module>guest\webservices\rest-server</module> --><!-- PMD voilation -->
|
||||||
<!-- <module>guest\webservices\spring-rest-service</module> --><!-- guest post on different site -->
|
<!-- <module>guest\webservices\spring-rest-service</module> --><!-- guest post on different site -->
|
||||||
@ -992,7 +992,7 @@
|
|||||||
<!-- <module>rule-engines/rulebook</module> --><!-- Wrong Parent -->
|
<!-- <module>rule-engines/rulebook</module> --><!-- Wrong Parent -->
|
||||||
<module>spring-boot-custom-starter/greeter</module>
|
<module>spring-boot-custom-starter/greeter</module>
|
||||||
<module>spring-boot-h2/spring-boot-h2-database</module>
|
<module>spring-boot-h2/spring-boot-h2-database</module>
|
||||||
<module>spring-boot-h2/spring-boot-h2-remote-app</module>
|
<!--module>spring-boot-h2/spring-boot-h2-remote-app</module-->
|
||||||
<!-- <module>guest\webservices\rest-client</module> --><!-- guest post on different site -->
|
<!-- <module>guest\webservices\rest-client</module> --><!-- guest post on different site -->
|
||||||
<!-- <module>guest\webservices\rest-server</module> --><!-- PMD voilation -->
|
<!-- <module>guest\webservices\rest-server</module> --><!-- PMD voilation -->
|
||||||
<!-- <module>guest\webservices\spring-rest-service</module> --><!-- guest post on different site -->
|
<!-- <module>guest\webservices\spring-rest-service</module> --><!-- guest post on different site -->
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
|
<!-- The main class to start by executing java -jar -->
|
||||||
|
<start-class>com.mycorp.starter.HelloWorldApplication</start-class>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.h2db.demo;
|
package com.baeldung.h2db.demo.client;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -7,16 +7,20 @@ import javax.annotation.PostConstruct;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@ComponentScan("com.baeldung.h2db.demo.client")
|
||||||
public class ClientSpringBootApp {
|
public class ClientSpringBootApp {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private JdbcTemplate jdbcTemplate;
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
System.setProperty("spring.datasource.url","jdbc:h2:tcp://localhost:9091/mem:mydb");
|
||||||
SpringApplication.run(ClientSpringBootApp.class, args);
|
SpringApplication.run(ClientSpringBootApp.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,4 +50,4 @@ public class ClientSpringBootApp {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.h2db.demo;
|
package com.baeldung.h2db.demo.server;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -9,10 +9,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@ComponentScan("com.baeldung.h2db.demo.server")
|
||||||
public class SpringBootApp {
|
public class SpringBootApp {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -24,8 +26,7 @@ public class SpringBootApp {
|
|||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void initDb() {
|
private void initDb() {
|
||||||
System.out.println(String.format(
|
System.out.println(String.format("****** Creating table: %s, and Inserting test data ******", "Employees"));
|
||||||
"****** Creating table: %s, and Inserting test data ******", "Employees"));
|
|
||||||
|
|
||||||
String sqlStatements[] = {
|
String sqlStatements[] = {
|
||||||
"drop table employees if exists",
|
"drop table employees if exists",
|
||||||
@ -57,4 +58,4 @@ public class SpringBootApp {
|
|||||||
public Server inMemoryH2DatabaseServer() throws SQLException {
|
public Server inMemoryH2DatabaseServer() throws SQLException {
|
||||||
return Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9091");
|
return Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9091");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,25 +0,0 @@
|
|||||||
/target/
|
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
|
||||||
|
|
||||||
### STS ###
|
|
||||||
.apt_generated
|
|
||||||
.classpath
|
|
||||||
.factorypath
|
|
||||||
.project
|
|
||||||
.settings
|
|
||||||
.springBeans
|
|
||||||
.sts4-cache
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
|
||||||
.idea
|
|
||||||
*.iws
|
|
||||||
*.iml
|
|
||||||
*.ipr
|
|
||||||
|
|
||||||
### NetBeans ###
|
|
||||||
/nbproject/private/
|
|
||||||
/build/
|
|
||||||
/nbbuild/
|
|
||||||
/dist/
|
|
||||||
/nbdist/
|
|
||||||
/.nb-gradle/
|
|
@ -1,55 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<groupId>com.baeldung.h2db</groupId>
|
|
||||||
<artifactId>spring-boot-h2-remote-app</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<description>Demo Spring Boot applications that access H2 in memory database created
|
|
||||||
in another Spring Boot application
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
|
||||||
<version>2.0.4.RELEASE</version>
|
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.h2database</groupId>
|
|
||||||
<artifactId>h2</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
@ -1,5 +0,0 @@
|
|||||||
spring.datasource.url=jdbc:h2:tcp://localhost:9091/mem:mydb
|
|
||||||
spring.datasource.driverClassName=org.h2.Driver
|
|
||||||
spring.datasource.username=sa
|
|
||||||
spring.datasource.password=
|
|
||||||
spring.jpa.hibernate.ddl-auto=create
|
|
Loading…
x
Reference in New Issue
Block a user