ulisesbocchio / jasypt-spring-boot

Jasypt integration for Spring boot
MIT License
2.87k stars 514 forks source link

overrides custom jasyptStringEncryptor "required a single bean, but 2 were found" #352

Open 1451762067 opened 1 year ago

1451762067 commented 1 year ago

I encountered a problem while using Jasypt in my Spring Boot project. According to the official documentation, to replace the default encryptor, I just need to manually inject a bean named "jasyptStringEncryptor" to replace the default StringEncryptor object. However, after I did this, Spring kept throwing an error "required a single bean, but 2 were found", indicating that the type was duplicated. I have checked many materials but to no avail. I have tried switching between Spring Boot 2 and Spring Boot 3, as well as JDK 8, 11, and 17, but the problem persists. Please refer to my code and error message below.

Could you please help me with this issue? Thank you very much! image image image

ahxinin commented 1 year ago

in the version 3.0.5, you can set the property jasypt.encryptor.bean with you customer bean name, in your case, it is jasyptStringEncryptor. after this, the spring will just load customer bean, to avoid create two beans, the other bean was DefaultLazyEncryptor