Jasypt (Java Simplified Encryption) is a popular library for encrypting sensitive information in your applications. Integrating Jasypt with Spring Boot 2.x and 3.0.0 can significantly enhance the security of your configuration properties. This blog will guide you through the integration process, providing you with a clear understanding and troubleshooting tips along the way.
Why Jasypt?
When developing Spring Boot applications, it’s crucial to ensure that sensitive information (like database passwords or API keys) is protected. Jasypt simplifies this process by allowing you to encrypt these properties, keeping them safe from prying eyes.
How to Integrate Jasypt with Spring Boot
There are three main methods to integrate Jasypt with your Spring Boot application:
- Method 1: Add the Starter Jar Deendency
- Method 2: Use @EnableEncryptableProperties Annotation
- Method 3: Use @EncryptablePropertySource Annotation
1. Method 1: Simply Add the Starter Jar
If your Spring Boot application uses the @SpringBootApplication or @EnableAutoConfiguration annotation, follow these steps:
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
By adding this dependency, encryptable properties are enabled across the entire Spring environment.
2. Method 2: Add @EnableEncryptableProperties
If you’re not using the auto-configuration annotations, add the necessary dependency:
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot</artifactId>
<version>3.0.5</version>
</dependency>
Then, include the @EnableEncryptableProperties annotation in your main configuration class:
@Configuration
@EnableEncryptableProperties
public class MyApplication {
...
}
This setup will ensure that encryptable properties can be used throughout your application.
3. Method 3: Use @EncryptablePropertySource
If you want to declare specific encryptable property sources, add the following dependency:
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot</artifactId>
<version>3.0.5</version>
</dependency>
Then, specify the properties like so:
@Configuration
@EncryptablePropertySource(name = "EncryptedProperties", value = "classpath:encrypted.properties")
public class MyApplication {
...
}
With this annotation, you can effectively manage which properties should be encrypted.
How Everything Works
When you integrate Jasypt using any of the above methods, it registers a Spring post-processor that decorates all PropertySource objects within the Spring environment. This allows them to detect when properties are encrypted and load them accordingly.
Troubleshooting Tips
While integrating Jasypt can be straightforward, you may run into some issues:
- Decryption Fails: Ensure that you’ve set the correct encryption password as a system property or command line argument.
- Property Not Found: Double-check that your property names in the encrypted files are correct and actually present in your specified property sources.
- Library Versions: Ensure that you’re using compatible versions of Spring Boot and Jasypt.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
In Closing
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

