Skip to content

Commit 5deb531

Browse files
corneilpedja4
authored andcommitted
BAEL-2105: Change for deployment to Cloud Foundry (eugenp#5060)
1 parent 2a12e9a commit 5deb531

6 files changed

Lines changed: 133 additions & 15 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
applications:
3+
- name: spring-boot-bootstrap
4+
memory: 768M
5+
random-route: true
6+
path: ../target/spring-boot-bootstrap-cf.jar
7+
env:
8+
SPRING_PROFILES_ACTIVE: cloud,mysql
9+
services:
10+
- spring-bootstrap-db

‎spring-boot-bootstrap/pom.xml‎

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>org.baeldung</groupId>
66
<artifactId>spring-boot-bootstrap</artifactId>
@@ -14,6 +14,17 @@
1414
<version>0.0.1-SNAPSHOT</version>
1515
<relativePath>../parent-boot-2</relativePath>
1616
</parent>
17+
<dependencyManagement>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.cloud</groupId>
21+
<artifactId>spring-cloud-dependencies</artifactId>
22+
<version>Finchley.SR1</version>
23+
<type>pom</type>
24+
<scope>import</scope>
25+
</dependency>
26+
</dependencies>
27+
</dependencyManagement>
1728

1829
<dependencies>
1930
<dependency>
@@ -28,10 +39,22 @@
2839
<groupId>org.springframework.boot</groupId>
2940
<artifactId>spring-boot-starter-data-jpa</artifactId>
3041
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.cloud</groupId>
44+
<artifactId>spring-cloud-starter</artifactId>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-cloud-connectors</artifactId>
49+
</dependency>
3150
<dependency>
3251
<groupId>com.h2database</groupId>
3352
<artifactId>h2</artifactId>
3453
</dependency>
54+
<dependency>
55+
<groupId>mysql</groupId>
56+
<artifactId>mysql-connector-java</artifactId>
57+
</dependency>
3558
<dependency>
3659
<groupId>org.springframework.boot</groupId>
3760
<artifactId>spring-boot-starter-security</artifactId>
@@ -55,6 +78,47 @@
5578
</dependencies>
5679

5780
<profiles>
81+
<profile>
82+
<id>cloudfoundry</id>
83+
<dependencies>
84+
<dependency>
85+
<groupId>org.springframework.cloud</groupId>
86+
<artifactId>spring-cloud-starter</artifactId>
87+
</dependency>
88+
<dependency>
89+
<groupId>org.springframework.boot</groupId>
90+
<artifactId>spring-boot-starter-cloud-connectors</artifactId>
91+
</dependency>
92+
</dependencies>
93+
<build>
94+
<resources>
95+
<resource>
96+
<directory>src/main/resources</directory>
97+
<excludes>
98+
<exclude>**/logback.xml</exclude>
99+
</excludes>
100+
</resource>
101+
</resources>
102+
<plugins>
103+
<plugin>
104+
<groupId>org.springframework.boot</groupId>
105+
<artifactId>spring-boot-maven-plugin</artifactId>
106+
<configuration>
107+
<finalName>${project.name}-cf</finalName>
108+
</configuration>
109+
</plugin>
110+
<plugin>
111+
<groupId>org.apache.maven.plugins</groupId>
112+
<artifactId>maven-compiler-plugin</artifactId>
113+
<configuration>
114+
<excludes>
115+
<exclude>**/cloud/config/*.java</exclude>
116+
</excludes>
117+
</configuration>
118+
</plugin>
119+
</plugins>
120+
</build>
121+
</profile>
58122
<profile>
59123
<id>autoconfiguration</id>
60124
<build>
@@ -112,7 +176,19 @@
112176
</build>
113177
</profile>
114178
</profiles>
115-
179+
<build>
180+
<plugins>
181+
<plugin>
182+
<groupId>org.apache.maven.plugins</groupId>
183+
<artifactId>maven-compiler-plugin</artifactId>
184+
<configuration>
185+
<excludes>
186+
<exclude>**/cloud/*.java</exclude>
187+
</excludes>
188+
</configuration>
189+
</plugin>
190+
</plugins>
191+
</build>
116192
<properties>
117193
<servlet.version>4.0.0</servlet.version>
118194
</properties>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.baeldung.cloud.config;
2+
3+
import org.springframework.cloud.config.java.AbstractCloudConfig;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.context.annotation.Profile;
7+
8+
import javax.sql.DataSource;
9+
10+
@Configuration
11+
@Profile("cloud")
12+
public class CloudDataSourceConfig extends AbstractCloudConfig {
13+
14+
@Bean
15+
public DataSource dataSource() {
16+
return connectionFactory().dataSource();
17+
}
18+
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
server.port = 8081
2+
3+
spring.application.name = Bootstrap Spring Boot
4+
5+
spring.thymeleaf.cache = false
6+
spring.thymeleaf.enabled=true
7+
spring.thymeleaf.prefix=classpath:/templates/
8+
spring.thymeleaf.suffix=.html
9+
10+
spring.security.user.name=john
11+
spring.security.user.password=123
12+
13+
spring.datasource.driver-class-name=org.h2.Driver
14+
spring.datasource.url=jdbc:h2:mem:bootapp;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
15+
spring.datasource.username=sa
16+
spring.datasource.password=
17+
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
18+
19+
server.error.path=/error
20+
server.error.whitelabel.enabled=false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
server.port = 8081
2-
3-
spring.application.name = Bootstrap Spring Boot
4-
1+
server.port=${port:8080}
2+
spring.application.name = Bootstrap Spring Cloud
53
spring.thymeleaf.cache = false
64
spring.thymeleaf.enabled=true
75
spring.thymeleaf.prefix=classpath:/templates/
86
spring.thymeleaf.suffix=.html
97

10-
spring.security.user.name=john
11-
spring.security.user.password=123
12-
13-
spring.datasource.driver-class-name=org.h2.Driver
14-
spring.datasource.url=jdbc:h2:mem:bootapp;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
15-
spring.datasource.username=sa
16-
spring.datasource.password=
17-
188
server.error.path=/error
19-
server.error.whitelabel.enabled=false
9+
server.error.whitelabel.enabled=false
10+
11+
spring.jpa.generate-ddl=true

0 commit comments

Comments
 (0)