iyuohz / ehcache-spring-annotations

Automatically exported from code.google.com/p/ehcache-spring-annotations
0 stars 0 forks source link

EhCacheInterceptor not triggering #87

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Using spring mvc 3.0, create a controller called MarketQuotesController 

2. Create a method like this one on the controller:

@RequestMapping(value="/commodity", method=RequestMethod.GET)
    public @ResponseBody Commodity getCommodity(@RequestParam int commodityId) {
        return this.getReferenceDataService().getCommodity(commodityId);
    }

3. Create an interface of a DAO to get the commodity:
public interface CommodityLookupDAO {
    public Commodity getCommodityById(Integer commodityId);
}

4. Create the implementation
public class CommodityLookupDAOImpl implements CommodityLookupDAO {
(...)
    @Override
    @Cacheable(cacheName="commodityCache")
    public Commodity getCommodityById(Integer commodityId) {
        return super.find(commoditySqlById, new CommodityLookupMapper(), commodityId);
    }
}

5.Implementing ReferenceDataService:

@Override
    public Commodity getCommodity(Integer id) {
        return commodityDAO.getCommodityById(id);
    }

6. Setting up this spring context:
<bean id="cacheManager" 
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">   
         <property name="configLocation" value="/WEB-INF/ehcache.xml" />
    </bean> 

    <ehcache:config cache-manager="cacheManager">
        <ehcache:evict-expired-elements interval="60" />
    </ehcache:config>

    <ehcache:annotation-driven cache-manager="cacheManager" />

7. Having this as ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">    

    <defaultCache eternal="false" maxElementsInMemory="500" overflowToDisk="false" />           

    <cache name="commodityCache" maxElementsInMemory="500" eternal="false" overflowToDisk="false" />  

 </ehcache>

8. Have spring injecting:
    -The implementation of the service in the controller.
    -The implementation of the DAO in the service.

What is the expected output? What do you see instead?

The expected output is the interceptor generating the key for the cache. This 
is all I get on the logging side after executing several requests to the 
"cached" method:

<oct 14 18:26:36.120> <DEBUG> <net.sf.ehcache.config.ConfigurationFactory:148> 
- Configuring ehcache from InputStream
<oct 14 18:26:36.139> <DEBUG> <net.sf.ehcache.config.BeanHandler:271> - 
Ignoring ehcache attribute xmlns:xsi
<oct 14 18:26:36.140> <DEBUG> <net.sf.ehcache.config.BeanHandler:271> - 
Ignoring ehcache attribute xsi:noNamespaceSchemaLocation
<oct 14 18:26:36.194> <DEBUG> <net.sf.ehcache.util.PropertyUtil:88> - 
propertiesString is null.
<oct 14 18:26:36.199> <DEBUG> <net.sf.ehcache.CacheManager:605> - No disk store 
path defined. Skipping disk store path conflict test.
<oct 14 18:26:36.200> <DEBUG> <net.sf.ehcache.config.ConfigurationHelper:184> - 
No CacheManagerEventListenerFactory class specified. Skipping...
<oct 14 18:26:36.248> <DEBUG> <net.sf.ehcache.Cache:949> - No 
BootstrapCacheLoaderFactory class specified. Skipping...
<oct 14 18:26:36.248> <DEBUG> <net.sf.ehcache.Cache:923> - CacheWriter factory 
not configured. Skipping...
<oct 14 18:26:36.257> <DEBUG> <net.sf.ehcache.config.ConfigurationHelper:96> - 
No CacheExceptionHandlerFactory class specified. Skipping...
<oct 14 18:26:36.262> <DEBUG> <net.sf.ehcache.Cache:949> - No 
BootstrapCacheLoaderFactory class specified. Skipping...
<oct 14 18:26:36.262> <DEBUG> <net.sf.ehcache.Cache:923> - CacheWriter factory 
not configured. Skipping...
<oct 14 18:26:36.262> <DEBUG> <net.sf.ehcache.config.ConfigurationHelper:96> - 
No CacheExceptionHandlerFactory class specified. Skipping...
<oct 14 18:26:36.290> <DEBUG> <net.sf.ehcache.Cache:1183> - Initialised cache: 
commodityCache
<oct 14 18:26:36.290> <DEBUG> <net.sf.ehcache.config.ConfigurationHelper:331> - 
CacheDecoratorFactory not configured. Skipping for 'commodityCache'.
<oct 14 18:26:36.291> <DEBUG> <net.sf.ehcache.config.ConfigurationHelper:360> - 
CacheDecoratorFactory not configured for defaultCache. Skipping for 
'commodityCache'.

What version of the product are you using? On what operating system?

1.2 at windows 7

Please provide any additional information below.
I can provide pom.xml info or whatever else if needed

Is there any way to check out why the interceptor it is not being called?

Original issue reported on code.google.com by FacundoD...@gmail.com on 14 Oct 2011 at 9:49

GoogleCodeExporter commented 8 years ago
Could you turn up logging for com.googlecode.ehcache.annotations to debug? Note 
that the library uses SLF4j so you'll need to make sure you have the 
appropriate SLF4j binding included for your logging system: 
http://www.slf4j.org/manual.html#binding

I'd be interested in output from that package during app context startup and 
any output during annotated method invocation.

Original comment by eric.dalquist on 15 Oct 2011 at 1:47

GoogleCodeExporter commented 8 years ago

I am not being able to get any logs from that package.... it should be logging:

log4j.xml:

    <appender name="eprsLog" class="org.apache.log4j.FileAppender">
        <param name="File" value="${EPRS_HOME}/log/eprs.log" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
                value="<%d{MMM dd HH:mm:ss.SSS}> <%p> <%C:%L> - %m%n" />
        </layout>
    </appender>

    <category name="net.sf.ehcache" additivity="false">
        <priority value="DEBUG" />
        <appender-ref ref="eprsLog" />
    </category>

    <category name="com.googlecode.ehcache" additivity="false">
        <priority value="DEBUG" />
        <appender-ref ref="eprsLog" />
    </category>

    <category name="com.googlecode.ehcache.annotations" additivity="false">
        <priority value="DEBUG" />
        <appender-ref ref="eprsLog" />
    </category>

This is part of my pom.xml

        <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
        <!--                  Logging                                -->
        <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j.version}</version>
            <!--<scope>runtime</scope>-->
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j.version}</version>
            <!--<scope>runtime</scope>-->
        </dependency>

Is there anything else I can provide?

Original comment by FacundoD...@gmail.com on 17 Oct 2011 at 2:47

GoogleCodeExporter commented 8 years ago
I'm at a bit of a loss, can you share the root element with the schema 
definitions from your spring app context file? 

Original comment by eric.dalquist on 18 Oct 2011 at 9:37

GoogleCodeExporter commented 8 years ago
I apologize for the delay. I had to deliver a solution and so I ended up using 
xml files and using aop :(
My spring app context context file had all the definitions as many blogs 
stated. It looks the interceptor was not being utilized...

Thanks!

Original comment by FacundoD...@gmail.com on 31 Oct 2011 at 9:00

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I am facing just the same problem, any one can help about the solution, please!

Original comment by wanxiang.xing@gmail.com on 15 Jul 2012 at 4:32