小编Rub*_*sMN的帖子

javanica中的Hystrix异步方法没有在spring-boot java应用程序中运行

我正在使用spring-cloud-starter(即具有所有微服务功能的spring boot).当我在使用javanica @HystrixCommand注释的组件中创建hystrix方法时,请按照javanica github网站(https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-javanica)上的说明进行操作该方法运行async,无论我是使用'Future <>'还是Reactive执行'Observable <>',都没有运行/执行,
java.lang.ClassCastException: springbootdemo.EricComponent$1 cannot be cast to springbootdemo.Eric每当我尝试拉取结果(在Future <>的情况下)或得到回调(在Reactive Execution的情况下......并且println不会触发,所以它确实没有运行).

public class Application { ...
}
@RestController
@RequestMapping(value = "/makebunchofcalls/{num}")
class EricController { ..

    @RequestMapping(method={RequestMethod.POST})
    ArrayList<Eric> doCalls(@PathVariable Integer num) throws IOException {
        ArrayList<Eric> ale = new ArrayList<Eric>(num);
        for (int i =0; i<num; i++) {
            rx.Observable<Eric> oe = this.ericComponent.doRestTemplateCallAsync(i);
            oe.subscribe(new Action1<Eric>() {
                @Override
                public void call(Eric e) {  // AT RUNTIME, ClassCastException
                    ale.add(e);
                }
            });
        }

        return ale;
    }

@Component
class EricComponent { …
Run Code Online (Sandbox Code Playgroud)

java hystrix spring-cloud

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

spring-cloud with ribbon/eureka/hystrix使用restTemplate无法设置连接/读取超时

我使用spring-cloud构建了一个spring boot应用程序,并希望在我的客户端应用程序(也是一个微服务)中使用RestTemplate,这样我就可以继续使用mockMvc进行集成测试.我正在使用我正在调用的服务中的客户端微服务和eureka客户端的默认ribbon/eureka/hystrix客户端设置.这是有效的(一旦我发现serviceIds是标识restTemplate中的服务端点的东西).我的问题是,我似乎无法更改restTemplate读取和连接超时,似乎默认为300毫秒.

电话详情:

`@Configuration
 @EnableAutoConfiguration
 @ComponentScan
 @EnableConfigurationProperties
 @EnableHystrix
 @EnableEurekaClient
public class Application { ... public static void main(String[] args) {} ... }

@Component
class EricComponentToDoHystrix {   // apparently this has to be a component for hystrix to work btw
    @Autowired
    RestTemplate restTemplate;
    ..
    @HystrixCommand(fallbackMethod="defaultRestTemplateCall")
    public void doRestTemplateCall() 
        ResponseEntity<String> result = restTemplate.getForEntity("http://someservice/doSomething", String.class);  // actually make a call
    ..
    }
}`
Run Code Online (Sandbox Code Playgroud)

使用包含以下内容的application.properties:

spring:
  cloud:
    client:
      serviceIds:
        - someservice

someservice:
  ribbon:
    #listOfServers: localhost:7080
    #NIWSServerListClassName: com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList

    # the eureka vipAddress of the target …
Run Code Online (Sandbox Code Playgroud)

spring-cloud

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

Logback和Spring Boot的新springProperty查找机制无法正常工作

我正在使用Spring Boot 1.3.0.RC1到spring-cloud Brixton.M2​​并且无法将spring boot属性拉入logback.xml,正如此功能所暗示的那样checkin 支持springProperty的logback配置

我正在使用.yml文件,并希望从bootstrap.yml或application.yml中提取应用程序名称.

的logback-spring.xml:

<configuration>
      <springProperty scope="context" name="myappName" source="spring.application.name"/>
      <contextName>${myappName}</contextName>
      <appender name="logFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <file>logs/${myappName}.log</file>
         ... 
      </appender>
      ...
</configuration>
Run Code Online (Sandbox Code Playgroud)

这里的文档Spring Boot Logback扩展没有多大帮助.

这个其他stackoverflow问题无法在logback.xml中使用Spring Property占位符是较旧的,也不适用于我.任何见解都会有所帮助.

每个请求,这是正在使用的相关依赖关系树

[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.3.0.RC1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.3.0.RC1:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.3.0.RC1:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.0.RC1:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.0.RC1:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile
[INFO] …
Run Code Online (Sandbox Code Playgroud)

java logback spring-boot

7
推荐指数
3
解决办法
1万
查看次数

使用Java而不是bootstrap.yml通过Eureka查找Spring Cloud Config Server

我正在尝试在我们的基础pom中构建代码,通过Eureka自动配置Spring Cloud Config服务器查找.我们这样做是为了避免模仿开发人员构建微服务的.yml属性.例如,我们想要java配置从这些属性触发的所有行为:

spring:
  application:
    name: MyMicroservice
  cloud:
    config:
      enabled: true
    server:
      prefix: /diagnostics/admin/config
    failFast: true
    discovery:
      enabled: true
      serviceId: echo

management:
  context-path: /diagnostics/admin

eureka:
  password: password
  client:
    serviceUrl:
      defaultZone: http://user:${eureka.password}@localhost:8761/eureka/
  instance:
    leaseRenewalIntervalInSeconds: 10
    statusPageUrlPath: /diagnostics/admin/info
    healthCheckUrlPath: /diagnostics/admin/health
Run Code Online (Sandbox Code Playgroud)

经过大量实验后,除了Eureka发现的配置服务器(导致没有覆盖的配置属性)之外,以下方法大部分都有效:

@Order(-1)
public class AdditionalBootstrapPropertySourceLocator implements PropertySourceLocator {

    @Override
    public PropertySource<?> locate(Environment environment) {
        Map<String, Object> theBootstrapYmlConfig = new HashMap<>();
        theBootstrapYmlConfig.put("spring.cloud.config.enabled", new Boolean(true));
        theBootstrapYmlConfig.put("spring.cloud.config.server.prefix", "/diagnostics/admin/config");
        theBootstrapYmlConfig.put("spring.cloud.config.failFast", new Boolean(true));
        theBootstrapYmlConfig.put("spring.cloud.config.discovery.enabled", new Boolean(true));
        theBootstrapYmlConfig.put("spring.cloud.config.discovery.serviceId", "echo");

        theBootstrapYmlConfig.put("management.context-path", "/diagnostics/admin");

        theBootstrapYmlConfig.put("eureka.client.serviceUrl.defaultZone", "http://user:password@localhost:8761/eureka/");
        theBootstrapYmlConfig.put("eureka.instance.leaseRenewalIntervalInSeconds", new Integer(10));
        theBootstrapYmlConfig.put("eureka.instance.statusPageUrlPath", "/diagnostics/admin/info"); …
Run Code Online (Sandbox Code Playgroud)

java spring-boot spring-cloud

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

使用Eureka服务集成测试Spring Boot服务

我正在试图弄清楚如何在使用Eureka的Spring Boot应用程序上构建集成测试.说我有一个测试

@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {Application.class})
public class MyIntegrationTest {
  @Autowired
  protected WebApplicationContext webAppContext;

  protected MockMvc mockMvc;
  @Autowired
  RestTemplate restTemplate;

  @Before
  public void setup() {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
  }

  @Test
  public void testServicesEdgeCases() throws Exception {

    // test no registered services
    this.mockMvc.perform(get("/api/v1/services").accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON))
        .andDo(print())
        .andExpect(status().isOk())
        .andExpect(jsonPath("$").value(jsonArrayWithSize(0)));

    }
}
Run Code Online (Sandbox Code Playgroud)

我在我的代码路径中有api调用:

DiscoveryManager.getInstance().getDiscoveryClient().getApplications();
Run Code Online (Sandbox Code Playgroud)

这将是NPE.discoveryClient返回null.如果我直接启动Spring启动应用程序并自己使用API​​,代码工作正常.我没有任何具体的配置文件使用.我是否需要为Eureka设置一些特殊的东西,以便为发现客户端进行测试构建?

java service-discovery spring-boot spring-cloud netflix-eureka

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

Hystrix Javanica后备不在Spring Cloud 1.0中工作

我基于@spencergibb feign-eureka spring cloud starter示例构建了一个超级简单的Hystrix短路示例.起初我以为我无法得到hystrix javanica默认的fallbackMethod因为假装触发..现在,删除假,hystrix默认的fallbackMethod仍然没有捕获异常.

的pom.xml

<parent>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-parent</artifactId>
    <version>1.0.0.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix</artifactId>
    </dependency>
    :
</dependencies>
Run Code Online (Sandbox Code Playgroud)

主文件:

@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrix
@RestController
public class HelloClientApplication {

  @Autowired
  HelloClientComponent helloClientComponent;

  @RequestMapping("/")
  public String hello() {
    return helloClientComponent.makeMultipleCalls();
  }

  public static void main(String[] args) {
    SpringApplication.run(HelloClientApplication.class, args);
  }
Run Code Online (Sandbox Code Playgroud)

}

HelloClientComponent.java(创建因为我知道javanica希望在spring托管组件或服务中):

@Component
public class HelloClientComponent {

@Autowired
RestTemplate restTemplate;

public String …
Run Code Online (Sandbox Code Playgroud)

spring-boot hystrix spring-cloud

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

亚马逊市场的Android应用程序未在Kindle Fire上显示

让应用程序在Kindle Fire上的亚马逊市场展示的诀窍是什么?

我已将我的Android应用程序提交到亚马逊商城,并在几个月前获得批准.当我在我的摩托罗拉Xoom或我妻子的Nexus One上搜索该应用程序(通过亚马逊商城)时,我能够找到它.在Kindle上搜索,无处可寻.

我在https://developer.amazon.com/help/faq.html上阅读了亚马逊关于Kindle Fire 的建议,并没有给出任何暗示它为什么不显示的提示.我的清单中有以下相关条目:

<supports-screens
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"
    android:resizeable="true"
    android:anyDensity="true"
    />
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="8" />
Run Code Online (Sandbox Code Playgroud)

android amazon kindle-fire

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