When I call the @CachePut
function, I get the error:
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'universalId' cannot be found on null.
universalId
is one of the fields of CreateAccountRequest
but it could not find and could not generate key in Redis cache. It uses spring-boot 3.3.4. My other project which uses spring-boot 3.3.4 and the same SPEL format (@CachePut(cacheNames = "IdentifierCache", key = "#userRoles.identifier", condition = "#root.target.caching=='enable'"))
does not have this issue and can save key in cache.
Why does this happen?
@CachePut(cacheNames = "account", key = "#createAccountRequest.universalId", cacheManager = "demoAccountCacheManager")
public AccountDetails createAccount(CreateAccountRequest createAccountRequest) {
AccountDetails accountDetails = new AccountDetails.Builder()
.universalId(createAccountRequest.getUniversalId())
.accountId(BigDecimal.valueOf(437))
.clientId(BigDecimal.valueOf(752))
.fileRolePresent(createAccountRequest.getUniversalId() != Keys.ACCOUNT_WITHOUT_EFILING_ROLE)
.cardRegistered(true)
.create();
this.accountDetailsCache.put(accountDetails);
return accountDetails;
}
public class CreateAccountRequest {
private String universalId;
private String firstName;
private String lastName;
private String middleName;
....
}
pom.xml
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>ca.bc.gov.open.jag</groupId>
<artifactId>efiling-demo-starter</artifactId>
<version>2.0.2</version>
<properties>
<java.version>17</java.version>
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
<log4j2.version>2.17.1</log4j2.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>ca.bc.gov.open</groupId>
<artifactId>spring-bceid-starter</artifactId>
</dependency>
<!-- Redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>ca.bc.gov.open.jag</groupId>
<artifactId>efiling-commons</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>ca.bc.gov.open</groupId>
<artifactId>spring-sftp-starter</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.3.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>ca.bc.gov.open.jag</groupId>
<artifactId>efiling-bom</artifactId>
<version>2.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<!--mapstruct mapper autogen-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
BOM file
<groupId>ca.bc.gov.open.jag</groupId>
<artifactId>efiling-bom</artifactId>
<version>2.0.2</version>
<properties>
<log4j2.version>2.17.1</log4j2.version>
<ca.bc.gov.open.version>1.0.1</ca.bc.gov.open.version>
<com.brsanthu.version>2.2</com.brsanthu.version>
<com.fasterxml.jackson.core.version>2.12.1</com.fasterxml.jackson.core.version>
<com.github.joschi.jackson.version>2.12.1</com.github.joschi.jackson.version>
<com.google.code.findbugs.version>3.0.2</com.google.code.findbugs.version>
<com.splunk.logging.version>1.11.2</com.splunk.logging.version>
<commons-io.version>2.14.0</commons-io.version>
<io.springfox.version>3.0.0</io.springfox.version>
<io.swagger.version>2.2.9</io.swagger.version>
<java.version>17</java.version>
<javax.validation.version>2.0.1.Final</javax.validation.version>
<javax.xml.bind.version>2.3.1</javax.xml.bind.version>
<joda-time.version>2.10.10</joda-time.version>
<net.rakugakibox.spring.boot.version>2.7.1</net.rakugakibox.spring.boot.version>
<org.apache.commons.version>3.11</org.apache.commons.version>
<org.apache.commons.collections.collections.version>4.2</org.apache.commons.collections.collections.version>
<org.apache.cxf.version>4.0.5</org.apache.cxf.version>
<org.apache.tika.version>1.24.1</org.apache.tika.version>
<org.apache.skywalking.version>8.4.0</org.apache.skywalking.version>
<org.codehaus.janino>3.1.3</org.codehaus.janino>
<org.glassfish.jersey.inject.version>3.1.3</org.glassfish.jersey.inject.version>
<org.junit.jupiter.version>5.7.1</org.junit.jupiter.version>
<org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
<org.mockito.mockito-all.version>1.10.19</org.mockito.mockito-all.version>
<org.mockito.mockito-core.version>3.6.0</org.mockito.mockito-core.version>
<org.openapitools.version>0.2.6</org.openapitools.version>
<org.springdoc.version>1.8.0</org.springdoc.version>
<org.threeten.version>1.5.1</org.threeten.version>
<ch.qos.logback.version>1.4.14</ch.qos.logback.version>
<org.apache.tomcat.embed.version>10.1.25</org.apache.tomcat.embed.version>
<org.json.version>20231013</org.json.version>
<org.springframework.security.version>6.3.3</org.springframework.security.version>
<org.springframework.version>6.1.13</org.springframework.version>
</properties>
<repositories>
<repository>
<id>splunk-artifactory</id>
<name>Splunk Releases</name>
<url>https://splunk.jfrog.io/artifactory/ext-releases-local/</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>ca.bc.gov.open</groupId>
<artifactId>spring-bceid-starter</artifactId>
<version>${ca.bc.gov.open.version}</version>
</dependency>
<dependency>
<groupId>ca.bc.gov.open</groupId>
<artifactId>spring-clamav-starter</artifactId>
<version>${ca.bc.gov.open.version}</version>
</dependency>
<dependency>
<groupId>ca.bc.gov.open</groupId>
<artifactId>spring-sftp-starter</artifactId>
<version>${ca.bc.gov.open.version}</version>
</dependency>
<dependency>
<groupId>ca.bc.gov.open</groupId>
<artifactId>bambora-payment-starter</artifactId>
<version>${ca.bc.gov.open.version}</version>
</dependency>
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>${com.brsanthu.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${com.fasterxml.jackson.core.version}</version>
</dependency>
<dependency>
<groupId>com.github.joschi.jackson</groupId>
<artifactId>jackson-datatype-threetenbp</artifactId>
<version>${com.github.joschi.jackson.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>${com.google.code.findbugs.version}</version>
</dependency>
<dependency>
<groupId>com.splunk.logging</groupId>
<artifactId>splunk-library-javalogging</artifactId>
<version>${com.splunk.logging.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${io.springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${io.springfox.version}</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${io.swagger.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${javax.validation.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${javax.xml.bind.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<dependency>
<groupId>net.rakugakibox.spring.boot</groupId>
<artifactId>logback-access-spring-boot-starter</artifactId>
<version>${net.rakugakibox.spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${org.apache.commons.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${org.apache.commons.collections.collections.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-features-logging</artifactId>
<version>${org.apache.cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${org.apache.cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${org.apache.cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${org.apache.cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>${org.apache.tika.version}</version>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-logback-1.x</artifactId>
<version>${org.apache.skywalking.version}</version>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-trace</artifactId>
<version>${org.apache.skywalking.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>${org.codehaus.janino}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${org.glassfish.jersey.inject.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${org.junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${org.junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${org.mockito.mockito-all.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${org.mockito.mockito-core.version}</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>${org.openapitools.version}</version>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>${org.threeten.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${org.springdoc.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${org.apache.tomcat.embed.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${org.json.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${org.springframework.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
2
Answers
I had the same error/issue with key names in
@Cacheable
annotations after upgrading a Spring Boot microservice to v3.3.4 from 3.1.x. I stumbled across a post on GitHub which indicated that this is due to a change in Spring Framework as of version 6.1.3. The post referenced a workaround using the parameter index in the key name instead of using the parameter name.For example, this syntax for cache key breaks after upgrade.
Whereas this syntax using the index of the parameter from the method signature works.
I changed cache key name syntax on all
@Cacheable
and@CacheEvict
annotations used by the affected microservice and it solved the error. At this point I don’t know the root cause of the issue as I have not investigated the changes made to the Spring Framework in 6.1.3 and beyond.ahuemmer, thank you! I changed the parameter name to the index of the parameter on cacheable key name and it just worked (‘EL1007E in Cachable changes’ exception went away). Finally, I saw my data in Redis. My current change is like this:
@CachePut(cacheNames = "account", key = "#p0.universalId", cacheManager = "demoAccountCacheManager")
This issue must be caused from version conflict because the parameter name also works on my experimental project spring-boot-start-web:3.3.4 (spring framework 6.1.13).