Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6976133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:27:27+00:00 2026-05-27T17:27:27+00:00

I am using java annotation based configuration for initializing ehcache based caching, with Spring

  • 0

I am using java annotation based configuration for initializing ehcache based caching, with Spring 3.1.

Here is the sample code…

@Configuration
@EnableCaching
public class EhcacheConfig implements CachingConfigurer {

    .....

    @Bean
    public CacheManager cacheManager() {
        .....
        EhCacheManagerFactoryBean bean = new EhCacheManagerFactoryBean();
        bean.setCacheManagerName(CACHE_MANAGER);
        bean.setShared(Boolean.TRUE);
        File file = new File(property + Constants.Slash + EHCACHE_XML);
        bean.setConfigLocation(new FileSystemResource(file));

        try {
            bean.afterPropertiesSet();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        EhCacheCacheManager cm = new EhCacheCacheManager();
        cm.setCacheManager(bean.getObject());
        return cm;
    }

    public KeyGenerator keyGenerator() {
        return new DefaultKeyGenerator();
    }
}

There is a valid ehcache.xml with 1 cache declared in it.

This is all the configuration that I have for initializing ehcache with Spring. There is no XML based initialization in the application.

At runtime, I have noticed that cacheManager() is initialized, as expected. After its successful execution, the code fails to complete the initialization by erring out in:

CachingInterceptor.afterPropertiesSet() ->

if (this.cacheManager == null) {
    throw new IllegalStateException("'cacheManager' is required");
}

I have done some investigation.

It appears that the problem occurs when CachingInterceptor is being initialized by ProxyCachingConfiguration.

ProxyCachingConfiguration is derived from AbstractCachingConfiguration.

AbstractCachingConfiguration has a method called:

@PostConstruct
protected void reconcileCacheManager()

This method is not invoked. Had it been invoked, the cacheManager instantiated in EhcacheConfig.cacheManger() would have been setup correctly for used by the CacheInterceptor.afterPropertiesSet().

I do not understand the reason why reconcileCacheManager() is not invoked before CacheInterceptor.afterPropertiesSet() is invoked.

Am I missing something? Can some one help me with the problem that I am facing?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:27:28+00:00Added an answer on May 27, 2026 at 5:27 pm

    First, you might consider extracting the initialization of the EhCacheManagerFactoryBean to its own @Bean method.

    This way you can simply instantiate, configure, and return the FactoryBean without having to invoke afterPropertiesSet() yourself. This ensures that the object is a properly-managed Spring bean and that it can receive any other callbacks in might register for (like DisposableBean#destroy()) in this particular case.

    Assuming that new @Bean method is named “ecmfb”, you can simply call ecmfb().getObject() from within your cacheManager() method, and you’ll be guaranteed at that point that the FactoryBean contract (i.e. afterPropertiesSet()) has been satisfied.

    Second, you might care to know that your @Bean methods can throw any exception you like. So for example if you did not choose to extract the FactoryBean as I suggest above, you could still simplify the situation by declaring a ‘throws Exception’ clause on your cacheManager @Bean method. This will save you the current try/catch noise.

    Finally, to address why the @PostConstruct method is not being called, let me ask how you’re bootstrapping the Spring container. If you’re working with AnnotationConfig(Web)ApplicationContext, the CommonAnnotationBeanPostProcessor should be registered by default. The same is true if you’re using or . CABPP is responsible for the detection and processing of annotations like @PostConstruct, @PreDestroy and others. Please provide a bit more information about your bootstrapping approach and we’ll go from there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to declare a bean using Spring 3's Java-based configuration, I can
I'm developing bunch of relatively small Spring based java web-application. I'm mostly using annotations
i have written a small webapp using spring-security and spring-mvc with an annotation based
I am developing a SAAS based java product using Spring 3 framework and using
What are the best practices for using Java's @Override annotation and why? It seems
I am using Java 1.4 with Log4J. Some of my code involves serializing and
I'm using Spring and Hibernate in a Java-EE application. The project is hosted at
I have an Java-Annotation that return a double value: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface DoubleValue
I'm using GraniteDS Actionscript code generation templates that let's me take a Java object
I'm experimenting with java annotation processors. I'm able to write integration tests using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.