Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoUniqueBeanDefinitionException: defaultTextEncryptor, kmsTextEncryptor #18

Closed
muatik opened this issue Aug 2, 2017 · 2 comments
Closed

Comments

@muatik
Copy link

muatik commented Aug 2, 2017

When I add spring-cloud-config-aws-kms into the pom.xml, shown below, I have a not unique bean error.

***************************
APPLICATION FAILED TO START
***************************

Description:

Field encryptor in org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration required a single bean, but 2 were found:
	- defaultTextEncryptor: defined by method 'defaultTextEncryptor' in org.springframework.cloud.config.server.config.EncryptionAutoConfiguration$DefaultTextEncryptorConfiguration
	- kmsTextEncryptor: defined by method 'kmsTextEncryptor' in de.zalando.spring.cloud.config.aws.kms.KmsEncryptionConfiguration$KmsTextEncryptorConfiguration

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.security.crypto.encrypt.TextEncryptor' available: expected single matching bean but found 2: defaultTextEncryptor,kmsTextEncryptor
        <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.4.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.8</java.version>
		<spring-cloud.version>Dalston.SR2</spring-cloud.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-config-server</artifactId>
			<version>1.3.2.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.zalando</groupId>
			<artifactId>spring-cloud-config-aws-kms</artifactId>
			<version>1.6</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
@kinow
Copy link
Contributor

kinow commented Aug 2, 2017

I believe it is due to your first dependency, which includes a TextEncryptor (org.springframework.cloud.config.server.config.EncryptionAutoConfiguration$DefaultTextEncryptorConfiguration).

Looking at the current code in Spring Cloud, I think even though there is a ConditionalOnMissingBean, the default still gets loaded as it is loaded before the zalando lib?

I'd first try disabling spring.cloud.config.server.encrypt.enabled, and then if that didn't work, would move the zalando dep to the top of the pom.

@muatik
Copy link
Author

muatik commented Aug 2, 2017

Moving Zalando's dependency to top worked for me, thanks.

@muatik muatik closed this as completed Aug 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants