标签: spring-cloud

Spring Boot (ConfigServer) 一直在重启

我们有一个非常简单的 Spring Boot Service ( @EnableConfigServer) 在 nginx 代理后面运行。

该服务基本上可以工作,但它一直在重新启动(上下文已关闭并连续启动)。

请参阅此处的日志文件:http : //pastebin.com/GErCF5x6

设置基本上只是一个 Java 类和两个配置(bootstrap.properties 和 application.properties)。

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.context.annotation.Configuration;

/**
 * Main Application, which starts the Spring Boot context
 */
@Configuration
@EnableAutoConfiguration
@EnableConfigServer
public class Application {

    @SuppressWarnings("PMD.SignatureDeclareThrowsException")
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

bootstrap.properties

spring.application.name = configserver
spring.cloud.config.enabled = false
encrypt.failOnError= false
encrypt.key= secret
Run Code Online (Sandbox Code Playgroud)

应用程序属性

# HTTP Configuration
server.port = 8888

# Management Configuration …
Run Code Online (Sandbox Code Playgroud)

nginx spring-boot spring-cloud

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

AWS CodeCommit HTTPS 访问,无需设置凭证助手

我们正在从 GitHub 过渡到 AWS CodeCommit,以拥有一个紧密集成的环境。

一种需求是通过 HTTPS 访问一个存储库。此存储库可通过使用 jgit 读取存储库并克隆文件以供其使用的 Spring Cloud Config Server 产品访问。

在通过 HTTPS 连接时,AWS CodeCommit 显然需要使用凭证助手,但我不这样设置。我想要一个 jgit 可以使用的用户和密码设置,而无需使用凭证助手生成临时凭证。有什么办法可以做到这一点吗?

有没有什么办法可以配置CodeCommit通过HTTPS访问一个固定的用户和密码来访问存储库?

git amazon-web-services spring-cloud aws-codecommit

5
推荐指数
2
解决办法
8015
查看次数

运行时Spring cloud Eureka报错

我正在尝试使用下面的 pom 创建一个 Spring cloud Eureka 服务器,主要来自 https://github.com/joshlong/service-registration-and-discovery

但是,我收到“创建名为 'viewControllerHandlerMapping' 的 bean 时出错”错误,由“java.lang.IllegalStateException:如果当前未启动资源可能无法访问”引起。

我认为这可能与拉取的各种 Jersey 组件的版本为 1.11 和 1.13 有关,尽管我没有看到任何单个 jar 被拉取两次。除此之外,我不知道为什么。有任何想法吗?提前致谢!

<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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.my.cloudconfig</groupId>
  <artifactId>eureka</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>eureka</name>

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

  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-eureka-server</artifactId>
      <version>1.0.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.2.7</version>
      </plugin>
    </plugins>
  </build>

</project>
Run Code Online (Sandbox Code Playgroud)

编辑

应用类:

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication
{

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

spring-boot spring-cloud

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

Spring Cloud Netflix:通过RequestInterceptor将主机请求参数传递给FeignClient

我正在使用 Eureka、Zuul 和 FeignClient 构建一个 Spring Cloud 项目(Brixton.M4 和 Spring Boot 1.3.1),我正在尝试添加多租户支持(租户由子域:tenant1.myservice.com 标识)。为此,我想以某种方式将原始子域与通过 Feign 从一个服务转发到另一个服务的请求一起传递,但我似乎无法找到正确的方法来做到这一点。

我有一个客户端,它公开一个@RestController,它调用一个@FeignClient 与我的后端通信,后端通过自己的@RestController 向客户端公开服务器操作。

@FeignClient 使用与服务器上的 @RestController 相同的接口:

@FeignClient(name = "product")
public interface ProductService extends IProductService {

}
Run Code Online (Sandbox Code Playgroud)

我目前想做的是在 RequestInterceptor 中设置一个标头:

@Component
public class MultiTenancyRequestInterceptor implements RequestInterceptor {

    private CurrentTenantProvider currentTenantProvider;

    @Autowired
    public MultiTenancyRequestInterceptor(CurrentTenantProvider currentTenantProvider) {
        this.currentTenantProvider = currentTenantProvider;
    }

    @Override
    public void apply(RequestTemplate template) {
        try {
            template.header("TENANT", currentTenantProvider.getTenant());
        } catch (Exception e) {
            // "oops"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的提供者类是一个简单的组件,我试图在其中注入请求/会话范围 bean:

@Component
public class CurrentTenantProvider …
Run Code Online (Sandbox Code Playgroud)

spring-mvc spring-boot spring-cloud netflix-feign netflix-zuul

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

Spring oauth2 hasRole 访问被拒绝

我真的是 OAuth2 的新手,并尝试在角色 auth.server 中构建一台服务器来授权用户,并尝试保留受保护的资源...

我有一些问题需要使用 ResourceServerConfigurerAdapter 来确保安全。似乎他忽略了从 userInfoUrl 中获取的所有角色......

所以这里的代码:

认证服务器

@SpringBootApplication
@EnableAuthorizationServer
@EnableResourceServer
@RestController
public class Oa2AuthServerApplication {

    @RequestMapping("/user")
    public Principal user(Principal user) {
        return user;
    }
    public static void main(String[] args) {
        SpringApplication.run(Oa2AuthServerApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

__

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("admin")
                .password("admin")
                .roles("ADMIN", "USER")
                .and()
                .withUser("user")
                .password("user")
                .roles("USER");
    }
}
Run Code Online (Sandbox Code Playgroud)

__

@Configuration
public class …
Run Code Online (Sandbox Code Playgroud)

spring spring-cloud spring-oauth2

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

Spring zuul代理不接受不记名令牌

我有一个 zuul 代理 ( http://localhost:8765 ) 服务于 angular web 应用程序 ( http://localhost:8080/app )。在 zuul 代理后面还有一个 oauth2 服务器(http://localhost:8899)。

Web 资源代理在http://localhost:8765/web 下,资源代理在http://localhost:8765/api 下。Zuul 代理无需身份验证即可提供静态 Web 资源。因此,第一次身份验证是通过 JSON 调用 (GET /api/user) 完成的,这当然会以 401 失败。

现在我将页面转发到“ http://localhost:8899/uaa/oauth/authorize?response_type=token&client_id=web&redirect_uri=http://localhost:8765/web/index.html ”以进行隐式授权 oauth 2 流程。我现在可以授权 Web 应用程序并转发回我的 Web 应用程序。令牌是 url 的一部分,我可以解析它。

恕我直言,我现在唯一要做的就是将此令牌添加为 Authorization 标头(例如 Authorization:Bearer 2829d5e2-4fbe-4f91-b74d-c99b2fe894a7)。但是 zuul 代理不会按照授权接受这个请求。

我正在使用 spring boot 1.3.2 和 spring cloud Brixton.M4。Zuul 服务器应用程序可以在这里找到,安全配置可以在这里找到。

这是我的请求标头:

Accept:application/json
Accept-Encoding:gzip, deflate, sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Authorization:Bearer 2829d5e2-4fbe-4f91-b74d-c99b2fe894a7
Connection:keep-alive
Cookie:XSRF-TOKEN=a6ddea36-e3b7-4f22-b80c-b4c8b6fd7760; JSESSIONID=DAE4649D11386D586A0CF739148E505A; …
Run Code Online (Sandbox Code Playgroud)

spring-security spring-cloud netflix-zuul

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

Spring Cloud Config Encryption API 忽略末尾的特殊字符

我们已经使用 Spring 云配置外部化了我们的应用程序配置。我们还使用加密 API 在纯文本密码进入 yaml 属性文件之前对其进行加密。

我正在努力为下游系统加密密码,该密码最后具有特殊字符。不知何故,云配置加密 API 忽略了这一点。当您使用解密 API 解密密码时,您会得到纯文本,最后没有特殊字符。

我正在使用 curl 来调用 API -

curl 10.102.82.1:11901/encrypt -d AXIzFDH4XZA=  
Run Code Online (Sandbox Code Playgroud)

出于某种原因,纯文本中间的特殊字符可以正常工作,但是如果最后有它,那么它会被忽略。可能这个密码已经被散列了,但我仍然很想知道如何处理这个问题。

java encryption spring spring-cloud

5
推荐指数
2
解决办法
1890
查看次数

Eureka服务器不适用于Spring Boot 2.0.0.M4

我试图将基于微服务的Web应用程序从Spring Boot 2.0.0.M3更新到最新的2.0.0.M4。

当运行我的Eureka服务器时,我面临以下异常,并且上下文不会加载:

2017-09-19 10:22:05.455  INFO 16388 --- [           main] o.s.core.annotation.AnnotationUtils      : Failed to introspect annotations on [class org.springframework.cloud.netflix.hystrix.HystrixAutoConfiguration$$EnhancerBySpringCGLIB$$5d536e23]: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
2017-09-19 10:22:05.456  INFO 16388 --- [           main] o.s.core.annotation.AnnotationUtils      : Failed to introspect annotations on [class org.springframework.cloud.netflix.hystrix.HystrixAutoConfiguration$$EnhancerBySpringCGLIB$$5d536e23]: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
2017-09-19 10:22:05.572  INFO 16388 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-09-19 10:22:05.573  INFO 16388 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-09-19 10:22:05.579  INFO 16388 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot spring-cloud netflix-eureka spring-cloud-netflix

5
推荐指数
0
解决办法
969
查看次数

&lt;aws-messaging:annotation-driven-queue-listener /&gt;的基于Java的配置版本是什么?

根据最新版本的Spring Cloud AWS文档(http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html),第5.2.3节指出,您需要QueueMessageHandler使用以下配置在传统的Spring XML配置中:

<aws-messaging:annotation-driven-queue-listener />
Run Code Online (Sandbox Code Playgroud)

您如何使用更现代的基于Java的配置来进行配置?

java spring spring-boot spring-cloud spring-cloud-aws

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

异常HandlerMethodArgumentResolversHolder

无法启动应用程序,使此消息出现以下异常。

尝试升级Java和Spring Boot父启动器时

 java.lang.IllegalStateException: Error processing condition on org.springframework.cloud.stream.config.BindingServiceConfiguration.bindingService
        at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:64)
        at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:181)
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141)
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader
Caused by: java.lang.NoClassDefFoundError: org/springframework/integration/config/HandlerMethodArgumentResolversHolder
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:668)
    ... 39 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.integration.config.HandlerMethodArgumentResolversHolder
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 43 common frames omitted
Run Code Online (Sandbox Code Playgroud)

pom.xml已升级了Spring Boot父启动器和Java

我是否需要为此添加任何其他Maven依赖项?

尝试添加spring-integration-core依赖性会导致不同的异常。

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

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.9</java.version>
            <springfox.version>2.6.0</springfox.version>
        </properties>


    <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId> …
Run Code Online (Sandbox Code Playgroud)

spring spring-integration spring-data spring-boot spring-cloud

5
推荐指数
2
解决办法
2773
查看次数