小编Yog*_*Rai的帖子

负载均衡器没有可用于客户端的服务器

我正在尝试使用Feign客户端.以下是我的客户:

import com.eprogrammerz.examples.domain.Movie;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by Yogen on 12/26/2016.
 */
@FeignClient(name = "movie-api")
public interface MovieApi {
    @RequestMapping(method = RequestMethod.GET, value = "/movies/{id}")
    Movie getMovie(@PathVariable("id") Long id);
}
Run Code Online (Sandbox Code Playgroud)

我从简单的服务中调用它,如下所示:

@Service
public class MovieService {

    @Autowired
    MovieApi movieApi;

    public Movie findMovie(Long id){
        Movie movieOfTheDay = movieApi.getMovie(id);
        return movieOfTheDay;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的春季启动应用程序如下:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.feign.EnableFeignClients;

@EnableFeignClients(basePackages = {"com.eprogrammerz.examples"})
@EnableCircuitBreaker
@SpringBootApplication
public class ClientAppApplication {

    public static void main(String[] …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot netflix-feign spring-cloud-netflix

18
推荐指数
4
解决办法
5万
查看次数

在Swagger2中隐藏/删除Spring MVC端点

我正在使用Swagger 2进行API UI.所以,我gradle.build有:

compile "io.springfox:springfox-swagger2:${swaggerVersion}"
compile "io.springfox:springfox-swagger-ui:${swaggerVersion}"
Run Code Online (Sandbox Code Playgroud)

我已将Swagger配置如下:

@Configuration
@Profile("!production")
@EnableSwagger2
@ComponentScan(basePackageClasses = com.company.controllers.ContentController.class)
public class SwaggerConfiguration {
    @Autowired
    private BuildInfo buildInfo;

    @Bean
    public Docket awesomeApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(this.awesomeApiInfo())
                .select()
                .apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot")))
                .build();

    }

    private ApiInfo awesomeApiInfo() {
        return new ApiInfoBuilder()
                .title("Awesome API - build #" + this.buildInfo.getVersion())
                .description("Enter the IDs in order to look for the content")
                .version("0.1")
                .build();
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在获取我已经定义的api端点,但也获得了如下的Spring MVC端点:

在此输入图像描述

现在,我需要摆脱这些mvc端点.

任何帮助都非常感谢!!

spring-mvc swagger swagger-ui spring-boot swagger-2.0

4
推荐指数
1
解决办法
5407
查看次数

EhCache缓存对象修改

我必须使用EhCache实现缓存。基本要求是,我必须将该缓存的对象保持固定的时间间隔(现在在下面的代码中保持1小时)。因此,我实现了如下代码:

样本域对象:

import lombok.*;
@Getter
@Setter
@ToString
@AllArgsConstructor
public class City implements Serializable {
    public String name;
    public String country;
    public int population;
}
Run Code Online (Sandbox Code Playgroud)

缓存管理器类:

import net.sf.ehcache.*;
public class JsonObjCacheManager {
    private static final Logger logger = LoggerFactory.getLogger(JsonObjCacheManager.class);
    private CacheManager manager;

    private Cache objectCache;

    public JsonObjCacheManager(){
        manager = CacheManager.create();

        objectCache =  manager.getCache("jsonDocCache");

        if( objectCache == null){
            objectCache = new Cache(
                    new CacheConfiguration("jsonDocCache", 1000)
                            .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
                            .eternal(false)
                            .timeToLiveSeconds(60 * 60)
                            .timeToIdleSeconds(0)
                            .diskExpiryThreadIntervalSeconds(0)
                            .persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP)));
            objectCache.disableDynamicFeatures();
            manager.addCache(objectCache);
        }
    }

    public List<String> …
Run Code Online (Sandbox Code Playgroud)

java caching ehcache ehcache-bigmemory jsr107

2
推荐指数
1
解决办法
1884
查看次数

找不到Gradle DSL方法:'compileOnly()'

我正在尝试将新模块添加到我的应用程序中.我成功添加了movie-api模块(你可以在下面的图片中看到),但是当我尝试添加另一个模块(客户端应用程序)时,我收到错误,如图所示. 在此输入图像描述

我尝试了不同的解决方案,包括没有找到的Gradle DSL方法:'compile()',但是对我来说不起作用.感谢您的帮助!

Build.gradle文件:

buildscript {
    ext {
        springBootVersion = '1.4.3.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'client-app'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    compileOnly('org.projectlombok:lombok')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)

intellij-idea gradle spring-boot

1
推荐指数
1
解决办法
3479
查看次数