Skip to content

Commit

Permalink
Convert to Spring Boot
Browse files Browse the repository at this point in the history
  • Loading branch information
scottfrederick committed Jul 1, 2016
1 parent 2fc8ba8 commit a3e3efb
Show file tree
Hide file tree
Showing 51 changed files with 117 additions and 452 deletions.
128 changes: 24 additions & 104 deletions build.gradle
@@ -1,15 +1,17 @@
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
springCloudConnectorsVersion = '1.2.2.RELEASE'
}

repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/plugins-release" }
}

dependencies {
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.2.5'
classpath 'org.cloudfoundry:cf-gradle-plugin:1.1.3'
classpath("io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE")
classpath("org.springframework.build.gradle:propdeps-plugin:0.0.7")
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

Expand All @@ -18,139 +20,57 @@ apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'

apply plugin: 'tomcat'
apply plugin: 'war'

apply plugin: 'cloudfoundry'

apply plugin: 'io.spring.dependency-management'
apply plugin: 'propdeps'
apply plugin: "propdeps-idea"
apply plugin: 'spring-boot'

version = '1.0'

sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/main/resources'
srcDir 'src/main/java'
}
}
}

sourceCompatibility = 1.7
targetCompatibility = 1.7
archivesBaseName = "spring-music"

jar {
manifest {
attributes 'Implementation-Title': 'Spring Sample Application', 'Implementation-Version': version
}
}

repositories {
mavenCentral()
maven { url "http://repo.spring.io/milestone" }
}

dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:2.0.0.RC1'
}
maven { url "http://repo.spring.io/snapshot" }
}

dependencies {
// Spring and dependencies
compile "org.springframework:spring-context"
compile "org.springframework:spring-webmvc"

// Spring Cloud
compile "org.springframework.cloud:spring-cloud-spring-service-connector"
compile "org.springframework.cloud:spring-cloud-cloudfoundry-connector"

// Spring Data
compile "org.springframework.data:spring-data-jpa"
compile "org.springframework.data:spring-data-redis"
compile "org.springframework.data:spring-data-mongodb"
// Spring Boot
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-data-mongodb"
compile "org.springframework.boot:spring-boot-starter-redis"

// Spring Cloud Connectors
compile "org.springframework.cloud:spring-cloud-core:${springCloudConnectorsVersion}"
compile "org.springframework.cloud:spring-cloud-spring-service-connector:${springCloudConnectorsVersion}"
compile "org.springframework.cloud:spring-cloud-cloudfoundry-connector:${springCloudConnectorsVersion}"

// JPA Persistence
compile "commons-dbcp:commons-dbcp"
compile "org.hibernate:hibernate-entitymanager"
runtime "com.h2database:h2"
runtime "mysql:mysql-connector-java"
runtime "postgresql:postgresql:9.1-901-1.jdbc4"

// Redis Persistence
compile "redis.clients:jedis"

// JSR-303 validation
compile "javax.validation:validation-api"
compile "org.hibernate:hibernate-validator"

// Webjars
compile "org.webjars:bootstrap:3.1.1"
compile "org.webjars:angularjs:1.2.16"
compile "org.webjars:angular-ui:0.4.0-2"
compile "org.webjars:angular-ui-bootstrap:0.10.0-1"
compile "org.webjars:jquery:2.1.0-2"

// Jackson
compile "org.codehaus.jackson:jackson-core-asl:1.9.13"
compile "org.codehaus.jackson:jackson-mapper-asl:1.9.13"
compile "com.fasterxml.jackson.core:jackson-core"
compile "com.fasterxml.jackson.core:jackson-databind"

// Logging
compile "org.slf4j:slf4j-api"
compile "org.slf4j:slf4j-log4j12"

// Servlet
compile "javax.servlet:jstl:1.2"
providedCompile 'javax.servlet:javax.servlet-api'

// Testing
testCompile "junit:junit"

// Spring Testing
testCompile "org.springframework:spring-test"

// Tomcat
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}"
tomcat "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
}

task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}

war {
// omit the version from the war file name
version = ""
}

tomcatRun {
outputFile = file('tomcat.log')
jar {
baseName = "spring-music"
version = "" // omit the version from the war file name
}

cloudfoundry {
target = "https://api.run.pivotal.io"
space = "development"

file = file("${war.archivePath}")
uri = "spring-music-${randomWord}.cfapps.io"
memory = 512
instances = 1

services {
"music-mongodb" {
label = "mongolab"
plan = "sandbox"
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.14'
}
1 change: 0 additions & 1 deletion gradle.properties
@@ -1 +0,0 @@
tomcatVersion=7.0.54
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Wed May 20 16:48:48 CDT 2015
#Fri Jul 01 14:31:42 EDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip
10 changes: 3 additions & 7 deletions gradlew
Expand Up @@ -42,11 +42,6 @@ case "`uname`" in
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
Expand All @@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

Expand Down Expand Up @@ -114,6 +109,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
Expand Down
5 changes: 2 additions & 3 deletions manifest.yml
@@ -1,8 +1,7 @@
---
applications:
- name: spring-music
memory: 512M
instances: 1
memory: 1G
random-route: true
path: build/libs/spring-music.war
path: build/libs/spring-music.jar

17 changes: 17 additions & 0 deletions src/main/java/org/cloudfoundry/samples/music/Application.java
@@ -0,0 +1,17 @@
package org.cloudfoundry.samples.music;

import org.cloudfoundry.samples.music.config.SpringApplicationContextInitializer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).
initializers(new SpringApplicationContextInitializer())
.application()
.run(args);
}
}

This file was deleted.

Expand Up @@ -12,18 +12,17 @@
import org.springframework.cloud.service.common.PostgresqlServiceInfo;
import org.springframework.cloud.service.common.RedisServiceInfo;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.StringUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

import java.util.*;

public class SpringApplicationContextInitializer implements ApplicationContextInitializer<AnnotationConfigWebApplicationContext> {
public class SpringApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

private static final Log logger = LogFactory.getLog(SpringApplicationContextInitializer.class);

private static final Map<Class<? extends ServiceInfo>, String> serviceTypeToProfileName =
new HashMap<Class<? extends ServiceInfo>, String>();
private static final Map<Class<? extends ServiceInfo>, String> serviceTypeToProfileName = new HashMap<>();
private static final List<String> validLocalProfiles = Arrays.asList("mysql", "postgres", "mongodb", "redis");

public static final String IN_MEMORY_PROFILE = "in-memory";
Expand All @@ -37,7 +36,7 @@ public class SpringApplicationContextInitializer implements ApplicationContextIn
}

@Override
public void initialize(AnnotationConfigWebApplicationContext applicationContext) {
public void initialize(ConfigurableApplicationContext applicationContext) {
Cloud cloud = getCloud();

ConfigurableEnvironment appEnvironment = applicationContext.getEnvironment();
Expand All @@ -60,7 +59,7 @@ public String[] getCloudProfile(Cloud cloud) {
return null;
}

List<String> profiles = new ArrayList<String>();
List<String> profiles = new ArrayList<>();

List<ServiceInfo> serviceInfos = cloud.getServiceInfos();

Expand Down Expand Up @@ -97,7 +96,7 @@ private Cloud getCloud() {
}

private String[] getActiveProfile(ConfigurableEnvironment appEnvironment) {
List<String> serviceProfiles = new ArrayList<String>();
List<String> serviceProfiles = new ArrayList<>();

for (String profile : appEnvironment.getActiveProfiles()) {
if (validLocalProfiles.contains(profile)) {
Expand Down

This file was deleted.

0 comments on commit a3e3efb

Please sign in to comment.