Skip to content

Commit a9bea07

Browse files
tschimanpivovarit
authored andcommitted
BAEL-1176 Spring Cloud Connector Heroku (eugenp#2911)
* BAEL-1176 setting up base application with in memory database * BAEL-1176 adding postgres stuff
1 parent 666206c commit a9bea07

8 files changed

Lines changed: 211 additions & 0 deletions

File tree

‎spring-cloud/pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<module>spring-cloud-rest</module>
1717
<module>spring-cloud-zookeeper</module>
1818
<module>spring-cloud-gateway</module>
19+
<module>spring-cloud-connectors-heroku</module>
1920
</modules>
2021
<packaging>pom</packaging>
2122

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<groupId>org.springframework.boot</groupId>
10+
<version>1.4.4.RELEASE</version>
11+
<relativePath />
12+
</parent>
13+
14+
<groupId>com.baeldung.spring.cloud</groupId>
15+
<artifactId>spring-cloud-connectors-heroku</artifactId>
16+
<version>1.0.0-SNAPSHOT</version>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-cloud-connectors</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-data-jpa</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-web</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-actuator</artifactId>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.postgresql</groupId>
38+
<artifactId>postgresql</artifactId>
39+
<version>9.4-1201-jdbc4</version>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>com.h2database</groupId>
44+
<artifactId>h2</artifactId>
45+
<scope>runtime</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
<dependencyManagement>
50+
<dependencies>
51+
<dependency>
52+
<groupId>org.springframework.cloud</groupId>
53+
<artifactId>spring-cloud-dependencies</artifactId>
54+
<version>${spring-cloud-dependencies.version}</version>
55+
<type>pom</type>
56+
<scope>import</scope>
57+
</dependency>
58+
</dependencies>
59+
</dependencyManagement>
60+
61+
<properties>
62+
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
63+
</properties>
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.springframework.boot</groupId>
69+
<artifactId>spring-boot-maven-plugin</artifactId>
70+
</plugin>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-surefire-plugin</artifactId>
74+
<version>2.19.1</version>
75+
<configuration>
76+
<forkCount>3</forkCount>
77+
<reuseForks>true</reuseForks>
78+
<excludes>
79+
<exclude>**/*IntegrationTest.java</exclude>
80+
<exclude>**/*LongRunningUnitTest.java</exclude>
81+
<exclude>**/*ManualTest.java</exclude>
82+
<exclude>**/JdbcTest.java</exclude>
83+
<exclude>**/*LiveTest.java</exclude>
84+
</excludes>
85+
<testFailureIgnore>true</testFailureIgnore>
86+
</configuration>
87+
</plugin>
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-compiler-plugin</artifactId>
91+
<version>3.6.0</version>
92+
<configuration>
93+
<source>1.8</source>
94+
<target>1.8</target>
95+
</configuration>
96+
</plugin>
97+
</plugins>
98+
</build>
99+
100+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.spring.cloud.connectors.heroku;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class ConnectorsHerokuApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(ConnectorsHerokuApplication.class, args);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.baeldung.spring.cloud.connectors.heroku.product;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.GenerationType;
6+
import javax.persistence.Id;
7+
8+
@Entity
9+
public class Product {
10+
@Id
11+
@GeneratedValue(strategy = GenerationType.IDENTITY)
12+
private Long productId;
13+
private String sku;
14+
15+
public Long getProductId() {
16+
return productId;
17+
}
18+
19+
public void setProductId(Long productId) {
20+
this.productId = productId;
21+
}
22+
23+
public String getSku() {
24+
return sku;
25+
}
26+
27+
public void setSku(String sku) {
28+
this.sku = sku;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.spring.cloud.connectors.heroku.product;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.web.bind.annotation.*;
5+
6+
@RestController
7+
@RequestMapping("/products")
8+
public class ProductController {
9+
10+
private final ProductService productService;
11+
12+
@Autowired
13+
public ProductController(ProductService productService) {
14+
this.productService = productService;
15+
}
16+
17+
@GetMapping("/{productId}")
18+
public Product findProduct(@PathVariable Long productId) {
19+
return productService.findProductById(productId);
20+
}
21+
22+
@PostMapping
23+
public Product createProduct(@RequestBody Product product) {
24+
return productService.createProduct(product);
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.baeldung.spring.cloud.connectors.heroku.product;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
5+
public interface ProductRepository extends JpaRepository<Product, Long>{
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.baeldung.spring.cloud.connectors.heroku.product;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.stereotype.Service;
5+
import org.springframework.transaction.annotation.Propagation;
6+
import org.springframework.transaction.annotation.Transactional;
7+
8+
@Service
9+
@Transactional(readOnly = true)
10+
public class ProductService {
11+
private final ProductRepository productRepository;
12+
13+
@Autowired
14+
public ProductService(ProductRepository productRepository) {
15+
this.productRepository = productRepository;
16+
}
17+
18+
public Product findProductById(Long productId) {
19+
return productRepository.findOne(productId);
20+
}
21+
22+
@Transactional(propagation = Propagation.REQUIRED)
23+
public Product createProduct(Product product) {
24+
Product newProduct = new Product();
25+
newProduct.setSku(product.getSku());
26+
return productRepository.save(newProduct);
27+
}
28+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
spring.datasource.driverClassName=org.postgresql.Driver
2+
spring.datasource.maxActive=10
3+
spring.datasource.maxIdle=5
4+
spring.datasource.minIdle=2
5+
spring.datasource.initialSize=5
6+
spring.datasource.removeAbandoned=true
7+
8+
spring.jpa.hibernate.ddl-auto=update

0 commit comments

Comments
 (0)