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

  • Home
  • SEARCH
  • 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 6576129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:28:23+00:00 2026-05-25T15:28:23+00:00

I have an interceptor in Spring, which autowires two different services. Both services have

  • 0

I have an interceptor in Spring, which autowires two different services.
Both services have methods that are tagged with @Cacheable from the ehcache-spring-annotations project, but with different cacheNames.

public class MenuInterceptor extends HandlerInterceptorAdapter {
    @Autowired
    private EventService eventService;

    @Autowired
    private OrganisationInfoService orgService;

    @Override
    public final void postHandle(HttpServletRequest request,
                       HttpServletResponse response,
                       Object handler,
                       ModelAndView modelAndView) throws SystemException {
        eventService.getFolderEventsForUser(123);
        orgService.getOrgCustomProfile("abc");

    }

@Service
public class EventServiceImpl implements EventService {
    @Override
    @Cacheable(cacheName = "ecomOrders")
    public Collection<FolderEventBean> getFolderEventsForUser(long loginId) throws SystemException {


@Service("organisationInfoService")
public class OrganisationInfoServiceImpl implements OrganisationInfoService {
    @Override
    @Cacheable(cacheName="orgProfile")
    public OrgCustomProfileBean getOrgCustomProfile(String orgHierarchyString) throws ServiceException {

When I run my application, one method successfully uses EHCache for the result, while the other does not. The OrganisationInfoSericeImpl.getOrgCustomProfile() caches properly, while the EventServiceImpl.getFolderEvnetsForUser does not. Can someone please tell me why?

I have tried to use same cache for both services, but still only one of them works.
I turned on DEBUG for ehcache-spring-annotations, and it registers both methods during startup:

[DEBUG] 08:09:01 () Adding CACHE advised method ‘getFolderEventsForUser’ with attribute: CacheableAttributeImpl [cache=[ name = ecomOrders status = STATUS_ALIVE eternal = false overflowToDisk = false maxElementsInMemory = 100 maxElementsOnDisk = 0 memoryStoreEvictionPolicy = LRU timeToLiveSeconds = 300 timeToIdleSeconds = 0 diskPersistent = false diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: net.sf.ehcache.statistics.LiveCacheStatisticsWrapper hitCount = 0 memoryStoreHitCount = 0 diskStoreHitCount = 0 missCountNotFound = 0 missCountExpired = 0 ], cacheKeyGenerator=HashCodeCacheKeyGenerator [includeMethod=true, includeParameterTypes=true, useReflection=false, checkforCycles=false], entryFactory=null, exceptionCache=null, parameterMask=ParameterMask [mask=[]]] [] at com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getMethodAttribute(CacheAttributeSourceImpl.java:174)

[DEBUG] 08:09:01 () Adding CACHE advised method ‘getOrgCustomProfile’ with attribute: CacheableAttributeImpl [cache=[ name = orgProfile status = STATUS_ALIVE eternal = false overflowToDisk = false maxElementsInMemory = 200 maxElementsOnDisk = 0 memoryStoreEvictionPolicy = LRU timeToLiveSeconds = 86400 timeToIdleSeconds = 0 diskPersistent = false diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: net.sf.ehcache.statistics.LiveCacheStatisticsWrapper hitCount = 0 memoryStoreHitCount = 0 diskStoreHitCount = 0 missCountNotFound = 0 missCountExpired = 0 ], cacheKeyGenerator=HashCodeCacheKeyGenerator [includeMethod=true, includeParameterTypes=true, useReflection=false, checkforCycles=false], entryFactory=null, exceptionCache=null, parameterMask=ParameterMask [mask=[]]] [] at com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getMethodAttribute(CacheAttributeSourceImpl.java:174)

When the interceptor calls the autowired services, only one of them caches:

[DEBUG] 08:09:19 (UNIQUE_ID) Generated key ‘-1668638847278617’ for invocation: ReflectiveMethodInvocation: public abstract no.finntech.base.modules.organisation.support.OrgCustomProfileBean no.finntech.service.organisation.OrganisationInfoService.getOrgCustomProfile(java.lang.String) throws no.finntech.service.ServiceException; target is of class [no.finntech.service.organisation.impl.OrganisationInfoServiceImpl] [URI: /finn/minfinn/myitems/list, Remote IP: 127.0.0.1, Referer: , User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2] at com.googlecode.ehcache.annotations.interceptor.EhCacheInterceptor.generateCacheKey(EhCacheInterceptor.java:272)

EDIT:
I should probably mention that the two services are defined in different maven modules.

  • 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-25T15:28:24+00:00Added an answer on May 25, 2026 at 3:28 pm

    It turns out the reason was related to context:component-scan.
    The service that failed to cache, was included in two different component scans. As soon as I resolved that the caching worked as expected.

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

Sidebar

Related Questions

I have a Spring Interceptor which attempts to add an HTTP header in the
I have a class which inherits from QTreeWidgetItem and I intercept the click event.
I am using declarative transactions in Spring. I have a service layer which is
I'va a ServiceImpl with is annotated with @Service stereotype of Spring and have two
Suppose we have an interface ICat that is derived from ICatBase and ICatExtension as
I have a basic Spring MVC controller that looks like this: @Controller public void
I have a small Spring (3.1.0.RELEASE) application, which was working just fine, until I
I have a web application that uses spring security. It uses <intercept-url ../> elements
I have some jQuery code that intercepts links clicked on a page: $(document).ready(function() {
I have an application that is working as a proxy using QTcpSocket to intercept

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.