xielq 4 anni fa
parent
commit
26395ca520

+ 58 - 11
build.gradle

@@ -1,25 +1,72 @@
-apply from: "$rootDir/gradle/service-base.gradle"
-/*apply from: "$rootDir/gradle/publish.gradle"
-apply from: "$rootDir/gradle/docker.gradle"*/
+buildscript {
+    ext {
+        springBootVersion = '1.5.9.RELEASE'
+    }
+    repositories {
+        maven { url 'https://plugins.gradle.org/m2/' }
+        maven { url 'http://repo.spring.io/plugins-release' }
+        maven { url 'http://113.105.74.141:8081/artifactory/libs-release-local' }
+        jcenter()
+    }
+    dependencies {
+        classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5")
+        classpath("com.uas.demo.mesh:spring-boot-docker-plugin:1.0.2")
+        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
+    }
+}
 
 group 'com.uas.cloud.mall'
-version '0.1.3'
+version '0.1.6-MESH'
 
-ext {
-    baseName = 'mall-carousel-service'
-    artifactId = 'mall-carousel-service'
+apply plugin: 'java'
+apply plugin: 'maven'
+apply plugin: 'eclipse'
+apply plugin: "org.springframework.boot"
+apply plugin: 'com.uas.docker.spring.boot'
+// apply plugin: "org.sonarqube"
+
+sourceCompatibility = 1.8
+
+repositories {
+    maven { url 'http://10.10.101.21:8081/artifactory/libs-snapshot' }
+    maven { url 'http://10.10.101.21:8081/artifactory/libs-release' }
+    maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
+    jcenter()
+    mavenCentral()
 }
 
-jar {
-    baseName = "${baseName}"
-    version = "${version}"
+ext {
+    springCloudVersion = 'Edgware.RELEASE'
 }
 
 dependencies {
+    compile "org.springframework.boot:spring-boot-starter-web"
+    compile "org.springframework.boot:spring-boot-actuator"
  	compile "org.springframework.boot:spring-boot-starter-data-jpa"
     compile "mysql:mysql-connector-java:5.1.21"
-    compile "org.springframework.cloud:spring-cloud-starter-eureka"
     compile "org.hibernate:hibernate-validator:$hibernateValidatorVersion"
+    compile("org.springframework.cloud:spring-cloud-starter-consul-discovery")
 
     compile "com.uas.cloud.base.commons:common:0.1.0"
 }
+
+dependencyManagement {
+    imports {
+        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
+    }
+}
+
+customDocker {
+    baseImage 'hub.c.163.com/library/java:8-jre-alpine'
+    registry '10.10.100.200:5000'
+}
+
+uploadArchives {
+    repositories {
+        mavenDeployer {
+            repository(url: "http://10.10.101.21:8081/artifactory/libs-release-local") {
+                authentication(userName: "yingp", password: "111111")
+            }
+        }
+    }
+}.dependsOn build

+ 0 - 40
gradle/docker.gradle

@@ -1,40 +0,0 @@
-buildscript {
-    ext {
-        springBootVersion = '1.4.4.RELEASE'
-    }
-    repositories {
-        maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
-        mavenCentral()
-        jcenter()
-    }
-    dependencies {
-        classpath('se.transmode.gradle:gradle-docker:1.2')
-    }
-}
-
-// apply plugin: 'docker'
-apply plugin: se.transmode.gradle.plugins.docker.DockerPlugin
-
-// 这里产生的镜像的标签会和 project。group一样,暂未找到解决办法
-// tag = "${project.group}/${applicationName}:${tagVersion}"
-task buildDocker(type:Docker, dependsOn: build) {
-    push = true
-//    applicationName = jar.baseName
-
-    tag = "10.10.100.200:5000/${jar.baseName}"
-    dockerfile = file('src/main/docker/Dockerfile')
-    doFirst {
-        copy {
-            from jar
-            into stageDir
-        }
-    }
-}
-
-docker {
-    hostUrl 'https://192.168.99.100:2376' // set the URL used to contact the Docker server. Defaults to http://localhost:2375
-    dockerBinary 'C:\\Program Files\\Docker Toolbox\\docker.exe'
-    useApi false // Use the Docker Remote API instead of a locally installed docker binary.
-    maintainer  'yangck'// The name and email address of the image maintainer.
-    registry '10.10.100.200:5000' // The hostname and port of the Docker image registry unless the Docker Hub Registry is used.
-}

+ 0 - 78
gradle/publish.gradle

@@ -1,78 +0,0 @@
-task sourcesJar(type: Jar) {
-    baseName "${baseName}"
-    classifier 'sources'
-    from sourceSets.main.allSource
-}
-artifacts {
-    archives sourcesJar
-}
-
-apply plugin: 'distribution'
-
-distributions {
-    main {
-        baseName = archivesBaseName
-
-        contents {
-            from { libsDir }
-        }
-    }
-
-    docs {
-        baseName = "$archivesBaseName-docs"
-
-        contents {
-            from(libsDir) {
-                include sourcesJar.archiveName
-            }
-        }
-    }
-}
-
-ext {
-    artifactoryBaseUrl = 'http://113.105.74.141:8081/artifactory'
-    artifactorySnapshotRepoUrl = "$artifactoryBaseUrl/libs-snapshot-local"
-    artifactoryReleaseRepoUrl = "$artifactoryBaseUrl/libs-release-local"
-}
-
-apply plugin: 'maven-publish'
-
-publishing {
-    publications {
-        plugin(MavenPublication) {
-            from components.java
-            artifactId "${artifactId}"
-
-            pom.withXml {
-                def root = asNode()
-                root.appendNode('name', "${baseName}")
-                root.appendNode('description', '商城轮播服务')
-                root.appendNode('inceptionYear', '2017')
-
-                def developer = root.appendNode('developers').appendNode('developer')
-                developer.appendNode('id', 'yangck')
-                developer.appendNode('name', '杨朝坤')
-                developer.appendNode('email', 'yangck@usoftchina.com')
-            }
-
-            artifact sourcesJar
-        }
-    }
-
-    repositories {
-        maven {
-            name 'myLocal'
-            url "file://$projectDir/repo"
-        }
-
-        maven {
-            name 'remoteArtifactory'
-            url project.version.endsWith('-SNAPSHOT') ? artifactorySnapshotRepoUrl : artifactoryReleaseRepoUrl
-
-            credentials {
-                username = 'yingp'
-                password = '111111'
-            }
-        }
-    }
-}

+ 0 - 74
gradle/service-base.gradle

@@ -1,74 +0,0 @@
-buildscript {
-    ext {
-        springBootVersion = '1.4.4.RELEASE'
-    }
-    repositories {
-        maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
-        maven { url "https://plugins.gradle.org/m2/" }
-        maven { url "https://repo.spring.io/libs-release" }
-        mavenCentral()
-        jcenter()
-    }
-    dependencies {
-        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
-    }
-}
-
-apply plugin: 'idea'
-apply plugin: 'eclipse'
-apply plugin: 'maven'
-apply plugin: 'java'
-//apply plugin: 'spring-boot'
-apply plugin: org.springframework.boot.gradle.plugin.SpringBootPlugin // applying a plugin by plugin id is not supported in script plugins. You must use the plugin's fully qualified class name.
-sourceCompatibility = 1.8 // 必须在apply java插件之后
-targetCompatibility = 1.8
-
-bootRun {
-    addResources = true
-}
-idea {
-    module {
-        downloadSources = true
-        downloadJavadoc = false
-        inheritOutputDirs = false
-        outputDir = file("$buildDir/classes/main/")
-    }
-}
-
-uploadArchives {
-    repositories {
-        mavenDeployer {
-            repository(url: "http://10.10.101.21:8081/artifactory/libs-release-local") {
-                authentication(userName: "yingp", password: "111111")
-            }
-        }
-    }
-}.dependsOn build
-
-repositories {
-    mavenLocal()
-    maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
-    maven {
-        url 'http://10.10.101.21:8081/artifactory/libs-release'
-    }
-    maven {
-        url 'http://10.10.101.21:8081/artifactory/libs-snapshot'
-    }
-    maven {
-        url 'http://10.10.101.21:8081/artifactory/plugins-snapshot'
-    }
-    mavenCentral()
-}
-
-dependencyManagement {
-    imports {
-        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR5'
-    }
-}
-dependencies {
-    testCompile 'org.springframework.boot:spring-boot-starter-test'
-    compile 'org.springframework.cloud:spring-cloud-starter-config'
-    // compile("org.springframework.boot:spring-boot-devtools")
-    compile "org.springframework.cloud:spring-cloud-starter-eureka"
-
-}

+ 5 - 0
gradle/wrapper/gradle-wrapper.properties

@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip

+ 172 - 0
gradlew

@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+    echo "$*"
+}
+
+die () {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+  NONSTOP* )
+    nonstop=true
+    ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+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`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Escape application args
+save () {
+    for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+    echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+  cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"

+ 84 - 0
gradlew.bat

@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega

+ 0 - 6
src/main/docker/Dockerfile

@@ -1,6 +0,0 @@
-FROM frolvlad/alpine-oraclejdk8:slim
-VOLUME /tmp # reate a temporary file on my host under "/var/lib/docker" and link it to the container under "/tmp".
-ADD mall-carousel-service-0.1.3.jar app.jar
-RUN sh -c "touch /app.jar" #  "touch" the jar file so that it has a file modification time (Docker creates all container files in an "unmodified" state by default). This actually isn’t important for the simple app that we wrote, but any static content (e.g. "index.html") would require the file to have a modification time.
-ENV JAVA_OPTS=""
-ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar --spring.profiles.active=test"] # To reduce Tomcat startup time we added a system property pointing to "/dev/urandom" as a source of entropy.

+ 4 - 3
src/main/java/com/uas/cloud/mall/carousel/CarouselApplication.java

@@ -1,8 +1,8 @@
 package com.uas.cloud.mall.carousel;
 
+import org.springframework.boot.Banner.Mode;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
-import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 
 /**
  * 轮播服务
@@ -10,10 +10,11 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  * @author yangck
  * @create 2017-02-16 10:14
  */
-@EnableDiscoveryClient
 @SpringBootApplication
 public class CarouselApplication {
     public static void main(String[] args) {
-        new SpringApplicationBuilder(CarouselApplication.class).web(true).run(args);
+        new SpringApplicationBuilder(CarouselApplication.class)
+                .bannerMode(Mode.OFF)
+                .web(true).run(args);
     }
 }

+ 30 - 30
src/main/java/com/uas/cloud/mall/carousel/api/CarouselController.java

@@ -4,20 +4,25 @@ import com.uas.cloud.base.commons.common.api.ResourceNotFoundException;
 import com.uas.cloud.base.commons.common.api.ServiceError;
 import com.uas.cloud.mall.carousel.domain.Carousel;
 import com.uas.cloud.mall.carousel.service.CarouselService;
+import java.net.URI;
+import java.util.List;
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cloud.client.ServiceInstance;
-import org.springframework.cloud.client.discovery.DiscoveryClient;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.util.UriComponentsBuilder;
 
-import java.net.URI;
-import java.util.List;
-
 /**
  * 轮播服务API
  *
@@ -30,25 +35,24 @@ public class CarouselController {
 
     private final Logger logger = LogManager.getLogger(getClass());
 
-    @Autowired
-    private DiscoveryClient client;
+    private final CarouselService carouselService;
 
     @Autowired
-    private CarouselService carouselService;
+    public CarouselController(CarouselService carouselService) {
+        this.carouselService = carouselService;
+    }
 
     @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json")
     public Carousel get(@PathVariable Long id) {
-        ServiceInstance instance = client.getLocalServiceInstance();
-        logger.info("/carousels, method: get, host:" + instance.getHost() + ", serviceId:" + instance.getServiceId() + ",carousel: " + id);
-        Carousel carousel = carouselService.findOne(id);
-        return carousel;
+        logger.info("/carousels, method: get, carousel: " + id);
+
+        return carouselService.findOne(id);
     }
 
     @RequestMapping(method = RequestMethod.POST, consumes = "application/json")
     @ResponseStatus(HttpStatus.CREATED)
     public ResponseEntity<Carousel> save(@RequestBody Carousel carousel, UriComponentsBuilder ucb) {
-        ServiceInstance instance = client.getLocalServiceInstance();
-        logger.info("/carousel, method: post, host: " + instance.getHost() + ", serviceId: " + instance.getServiceId() + "usedFor: " + carousel.getUsedFor());
+        logger.info("/carousel, method: post, usedFor: " + carousel.getUsedFor());
 
         Carousel saved = carouselService.save(carousel);
 
@@ -59,42 +63,37 @@ public class CarouselController {
                 .toUri();
         headers.setLocation(locationUri);
 
-        ResponseEntity<Carousel> responseEntity = new ResponseEntity<>(saved, headers, HttpStatus.CREATED);
-        return responseEntity;
+        return new ResponseEntity<>(saved, headers, HttpStatus.CREATED);
     }
 
     @RequestMapping(method = RequestMethod.PUT, consumes = "application/json")
     @ResponseStatus(HttpStatus.OK)
     public ResponseEntity<Carousel> update(@RequestBody Carousel carousel) {
-        ServiceInstance instance = client.getLocalServiceInstance();
-        logger.info("/carousel, method: put, host: " + instance.getHost() + ", serviceId: " + instance.getServiceId() + "usedFor: " + carousel.getUsedFor());
+        logger.info("/carousel, method: put, usedFor: " + carousel.getUsedFor());
 
         Carousel saved = carouselService.save(carousel);
 
-        ResponseEntity<Carousel> responseEntity = new ResponseEntity<>(saved, HttpStatus.OK);
-        return responseEntity;
+        return new ResponseEntity<>(saved, HttpStatus.OK);
     }
 
-
     @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
     public void delete(@PathVariable Long id) {
-        ServiceInstance instance = client.getLocalServiceInstance();
-        logger.info("/carousels, method: delete, host:" + instance.getHost() + ", serviceId:" + instance.getServiceId() + ",carousel: " + id);
+        logger.info("/carousels, method: delete, carousel: " + id);
+
         carouselService.delete(id);
     }
 
     @RequestMapping(method = RequestMethod.GET, produces = "application/json")
     public List<Carousel> carousels(@RequestParam(value = "usedFor", defaultValue = "home") String usedFor) {
-        ServiceInstance instance = client.getLocalServiceInstance();
-        logger.info("/carousel, get, host:" + instance.getHost() + ", serviceId:" + instance.getServiceId() + ",usedFor: " + usedFor);
-        List<Carousel> carousels = carouselService.findByUsedFor(usedFor);
-        return carousels;
+        logger.info("/carousel, get, usedFor: " + usedFor);
+
+        return carouselService.findByUsedFor(usedFor);
     }
 
     @GetMapping(value = "/usedFor", produces = "application/json")
     public List<String> getUsedFor() {
-        ServiceInstance instance = client.getLocalServiceInstance();
-        logger.info("/carousel/usedFor, get, host:" + instance.getHost() + ", serviceId:" + instance.getServiceId());
+        logger.info("/carousel/usedFor, get");
+
         return carouselService.getUsedFor();
     }
 
@@ -102,6 +101,7 @@ public class CarouselController {
     @ResponseStatus(HttpStatus.NOT_FOUND)
     public ServiceError resourceNotFound(ResourceNotFoundException e) {
         Long resourceId = e.getResourceId();
+
         return new ServiceError(4, "Carousel [" + resourceId + "] not found");
     }
 }

+ 1 - 1
src/main/java/com/uas/cloud/mall/carousel/data/CarouselRepository.java

@@ -16,7 +16,7 @@ import java.util.List;
 @Repository
 public interface CarouselRepository extends JpaRepository<Carousel, Long> {
 
-    List<Carousel> findByUsedForOrderByOrderNumber(String usedFor);
+    List<Carousel> findByUsedFor(String usedFor);
 
     Carousel save(Carousel carousel);
 

+ 1 - 1
src/main/java/com/uas/cloud/mall/carousel/service/impl/CarouselServiceImpl.java

@@ -22,7 +22,7 @@ public class CarouselServiceImpl implements CarouselService {
 
     @Override
     public List<Carousel> findByUsedFor(String usedFor) {
-        return carouselRepository.findByUsedForOrderByOrderNumber(usedFor);
+        return carouselRepository.findByUsedFor(usedFor);
     }
 
     @Override

+ 0 - 5
src/main/resources/application-dev.yml

@@ -14,8 +14,3 @@ spring:
     username: root
     password: select
     driver-class-name: com.mysql.jdbc.Driver
-
-eureka:
-  client:
-    serviceUrl:
-      defaultZone: http://10.10.100.23:28000/eureka/

+ 27 - 0
src/main/resources/application-mesh.yml

@@ -0,0 +1,27 @@
+spring:
+  jpa:
+#    hibernate:
+#      ddl-auto:
+#        create-drop
+    properties:
+      hibernate:
+        hbm2ddl:
+          auto: update
+    # disable open EntityManager in View
+    open-in-view: false
+  datasource:
+    url: jdbc:mysql://10.10.100.18:3306/mall_home?useUnicode=true&characterEncoding=utf-8
+    username: root
+    password: select
+    driver-class-name: com.mysql.jdbc.Driver
+  cloud:
+    consul:
+      host: consul
+      port: 8500
+      discovery:
+        tags: dev
+        instanceId: ${spring.application.name}:${vcap.application.instance_id:${spring.application.instance_id:${random.value}}}
+
+
+server:
+  port: 8080

+ 0 - 8
src/main/resources/application-prod.yml

@@ -16,11 +16,3 @@ spring:
     username: sa
     password: Select123!#%*(
     driver-class-name: com.mysql.jdbc.Driver
-
-eureka:
-  client:
-    serviceUrl:
-      defaultZone: http://10.10.0.187:28000/eureka/
-  instance:
-    ip-address: 10.10.0.188
-    prefer-ip-address: true

+ 14 - 2
src/main/resources/application.yml

@@ -1,6 +1,18 @@
-
 server:
   port: 20030
+
+management:
+  security:
+    enabled: false
+
+endpoints:
+  shutdown:
+    enabled: true
+
 spring:
+  application:
+    name: mall-carousel-service
+  main:
+    banner-mode: "off"
   profiles:
-    active: dev
+    active: dev

+ 0 - 0
src/main/resources/bootstrap-dev.yml


+ 0 - 1
src/main/resources/bootstrap-prod.yml

@@ -1 +0,0 @@
-

+ 0 - 0
src/main/resources/bootstrap-test.yml


+ 0 - 1
src/main/resources/bootstrap.yml

@@ -1 +0,0 @@
-

+ 0 - 55
src/test/java/com/uas/cloud/mall/carousel/CarouselApplicationTest.java

@@ -1,55 +0,0 @@
-package com.uas.cloud.mall.carousel;
-
-import com.uas.cloud.mall.carousel.domain.Carousel;
-import com.uas.cloud.mall.carousel.service.CarouselService;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.SpringApplicationConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Created by yangck on 2017/2/16.
- */
-/*@RunWith(SpringJUnit4ClassRunner.class)
-@SpringApplicationConfiguration(CarouselApplication.class)*/
-public class CarouselApplicationTest {
-
-   /* @Autowired
-    private CarouselService carouselService;
-
-    @Before
-    public void before() {
-        carouselService.deleteAll();
-    }
-
-    @Test
-    public void carouselTestData() {
-        Carousel carousel1 = new Carousel(null, "home", 0L, "http://dfs.ubtob.com/group1/M00/17/F3/CgpkyFjaM62AQafMAACiyPLUFOk177.jpg", "", "http://mall.ubtob.com/product#/kinds/100", null, "轮播1");
-        Map<String, String> metadata = new HashMap<>();
-        metadata.put("background-color", "#db143c");
-        carousel1.setMetadata(metadata);
-        carouselService.save(carousel1);
-
-        Carousel carousel2 = new Carousel(null, "home", 100L, "http://dfs.ubtob.com/group1/M00/17/F3/CgpkyFjaM5aAV7RiAADmRfkFf9w389.jpg", null, "http://mall.ubtob.com/product#/kinds/100", null, "轮播2");
-        metadata.put("background-color", "#ff98be");
-        carousel2.setMetadata(metadata);
-        carouselService.save(carousel2);
-
-
-        Carousel carousel3 = new Carousel(null, "store", 0L, "http://dfs.ubtob.com/group1/M00/17/F3/CgpkyFjaM62AQafMAACiyPLUFOk177.jpg", "", "http://mall.ubtob.com/product#/kinds/100", null, "轮播1");
-        metadata.put("background-color", "#db143c");
-        carousel3.setMetadata(metadata);
-        carouselService.save(carousel3);
-
-        Carousel carousel4 = new Carousel(null, "store", 100L, "http://dfs.ubtob.com/group1/M00/17/F3/CgpkyFjaM5aAV7RiAADmRfkFf9w389.jpg", null, "http://mall.ubtob.com/product#/kinds/100", null, "轮播2");
-        metadata.put("background-color", "#ff98be");
-        carousel4.setMetadata(metadata);
-        carouselService.save(carousel4);
-    }*/
-
-}