BAEL-2105: Change for deployment to Cloud Foundry (#5060)

This commit is contained in:
Corneil du Plessis 2018-08-30 01:00:11 +02:00 committed by Predrag Maric
parent 2a12e9abd4
commit 5deb5311f8
6 changed files with 133 additions and 15 deletions

View File

@ -0,0 +1,10 @@
---
applications:
- name: spring-boot-bootstrap
memory: 768M
random-route: true
path: ../target/spring-boot-bootstrap-cf.jar
env:
SPRING_PROFILES_ACTIVE: cloud,mysql
services:
- spring-bootstrap-db

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
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>org.baeldung</groupId>
<artifactId>spring-boot-bootstrap</artifactId>
@ -14,6 +14,17 @@
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
@ -28,10 +39,22 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cloud-connectors</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
@ -55,6 +78,47 @@
</dependencies>
<profiles>
<profile>
<id>cloudfoundry</id>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cloud-connectors</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/logback.xml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<finalName>${project.name}-cf</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/cloud/config/*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>autoconfiguration</id>
<build>
@ -112,7 +176,19 @@
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/cloud/*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<servlet.version>4.0.0</servlet.version>
</properties>

View File

@ -0,0 +1,19 @@
package org.baeldung.cloud.config;
import org.springframework.cloud.config.java.AbstractCloudConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import javax.sql.DataSource;
@Configuration
@Profile("cloud")
public class CloudDataSourceConfig extends AbstractCloudConfig {
@Bean
public DataSource dataSource() {
return connectionFactory().dataSource();
}
}

View File

@ -0,0 +1,20 @@
server.port = 8081
spring.application.name = Bootstrap Spring Boot
spring.thymeleaf.cache = false
spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.security.user.name=john
spring.security.user.password=123
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:bootapp;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
server.error.path=/error
server.error.whitelabel.enabled=false

View File

@ -0,0 +1 @@
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

View File

@ -1,19 +1,11 @@
server.port = 8081
spring.application.name = Bootstrap Spring Boot
server.port=${port:8080}
spring.application.name = Bootstrap Spring Cloud
spring.thymeleaf.cache = false
spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.security.user.name=john
spring.security.user.password=123
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:bootapp;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=
server.error.path=/error
server.error.whitelabel.enabled=false
server.error.whitelabel.enabled=false
spring.jpa.generate-ddl=true