dbpete
04-01-2008, 02:25 PM
Hello All,
I'm new with Spring.Net and have managed to implement Spring.Net successfully in our web application. I have run into an issue that I can't seem to figure out and hopefully someone here can point out what I did wrong. I cannot get the Spring.Net caching to work. I receive no errors. I'm using the latest release of Spring.NET and here are the details specific to my setup:
Web.config settings:
<configSections>
<sectionGroup name="spring">
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHand ler, Spring.Core" />
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web" />
</sectionGroup>
</configSections>
<spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
</parsers>
<context>
<resource uri="/config/Spring.xml" />
</context>
</spring>
Spring.xml:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:db="http://www.springframework.net/database">
<!-- Property placeholder configurer for database settings -->
<object type="Spring.Objects.Factory.Config.PropertyPlaceholderC onfigurer, Spring.Core">
<property name="ConfigSections" value="databaseSettings"/>
</object>
<!-- Production Data Access Objects -->
<db:provider id="dbProvider"
provider="SqlServer-2.0"
connectionString="Data Source=${db.server};Initial Catalog=${db.database};User ID=${db.user}; Password=${db.password}"/>
<object id="adoTemplate" type="Spring.Data.Core.AdoTemplate, Spring.Data">
<property name="DbProvider" ref="dbProvider"/>
</object>
<object id="myDao" type="myproject.core.dao.impl.MyDaoImpl, my.core">
<property name="AdoTemplate" ref="adoTemplate"/>
</object>
<object id="myServiceTarget" type="myproject.core.service.impl.MyServiceImpl, my.core">
<property name="myDao" ref="myDao" />
</object>
<object id="myService" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="Target" ref="myServiceTarget" />
<property name="ProxyInterfaces">
<value>myproject.service.IMyService</value>
</property>
</object>
<!-- Caching Methods -->
<object id="CacheAspect" type="Spring.Aspects.Cache.CacheAspect, Spring.Aop"/>
<object id="AspNetCache" type="Spring.Caching.AspNetCache, Spring.Web">
<property name="SlidingExpiration" value="true"/>
<property name="Priority" value="Low"/>
<property name="TimeToLive" value="02:02:00"/>
</object>
<object type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxy Creator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>*DaoImpl</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>CacheAspect</value>
</list>
</property>
</object>
</objects>
MyDaoImpl.cs (dao layer)
namespace myproject.core.dao.impl
{
public class MyDaoImpl : AdoDaoSupport, IMyDao
{
private static readonly ILog logger = LogManager.GetLogger(typeof(MyDaoImpl));
[CacheResult("AspNetCache", "", TimeToLive = "5:1:0")]
public String GetStuff()
{
logger.Debug("INSIDE STUFF!!");
return "stuff";
}
}
}
MyServiceImpl.cs (service layer)
namespace myproject.core.service.impl
{
public class MyServiceImpl : IMyService
{
private IMyDao myDao;
public MyServiceImpl()
{
}
public MyServiceImpl(IMyDao myDao)
{
this.myDao = myDao;
}
public String GetStuff()
{
return myDao.GetStuff();
}
}
}
The aspx page that calls the MyService:
private void Page_Load(object sender, System.EventArgs e)
{
logger.Debug("Loading page");
IApplicationContext ctx = ContextRegistry.GetContext();
IMyService myService = ctx.GetObject("myService") as IMyService;
String stuff = myService.GetStuff();
}
Every page request causes the logging message in the DAO method regardless if I have caching applied or not. I'm assuming I do not have this configured correctly.
Thanks in advance for any help!
I'm new with Spring.Net and have managed to implement Spring.Net successfully in our web application. I have run into an issue that I can't seem to figure out and hopefully someone here can point out what I did wrong. I cannot get the Spring.Net caching to work. I receive no errors. I'm using the latest release of Spring.NET and here are the details specific to my setup:
Web.config settings:
<configSections>
<sectionGroup name="spring">
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHand ler, Spring.Core" />
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web" />
</sectionGroup>
</configSections>
<spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
</parsers>
<context>
<resource uri="/config/Spring.xml" />
</context>
</spring>
Spring.xml:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:db="http://www.springframework.net/database">
<!-- Property placeholder configurer for database settings -->
<object type="Spring.Objects.Factory.Config.PropertyPlaceholderC onfigurer, Spring.Core">
<property name="ConfigSections" value="databaseSettings"/>
</object>
<!-- Production Data Access Objects -->
<db:provider id="dbProvider"
provider="SqlServer-2.0"
connectionString="Data Source=${db.server};Initial Catalog=${db.database};User ID=${db.user}; Password=${db.password}"/>
<object id="adoTemplate" type="Spring.Data.Core.AdoTemplate, Spring.Data">
<property name="DbProvider" ref="dbProvider"/>
</object>
<object id="myDao" type="myproject.core.dao.impl.MyDaoImpl, my.core">
<property name="AdoTemplate" ref="adoTemplate"/>
</object>
<object id="myServiceTarget" type="myproject.core.service.impl.MyServiceImpl, my.core">
<property name="myDao" ref="myDao" />
</object>
<object id="myService" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="Target" ref="myServiceTarget" />
<property name="ProxyInterfaces">
<value>myproject.service.IMyService</value>
</property>
</object>
<!-- Caching Methods -->
<object id="CacheAspect" type="Spring.Aspects.Cache.CacheAspect, Spring.Aop"/>
<object id="AspNetCache" type="Spring.Caching.AspNetCache, Spring.Web">
<property name="SlidingExpiration" value="true"/>
<property name="Priority" value="Low"/>
<property name="TimeToLive" value="02:02:00"/>
</object>
<object type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxy Creator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>*DaoImpl</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>CacheAspect</value>
</list>
</property>
</object>
</objects>
MyDaoImpl.cs (dao layer)
namespace myproject.core.dao.impl
{
public class MyDaoImpl : AdoDaoSupport, IMyDao
{
private static readonly ILog logger = LogManager.GetLogger(typeof(MyDaoImpl));
[CacheResult("AspNetCache", "", TimeToLive = "5:1:0")]
public String GetStuff()
{
logger.Debug("INSIDE STUFF!!");
return "stuff";
}
}
}
MyServiceImpl.cs (service layer)
namespace myproject.core.service.impl
{
public class MyServiceImpl : IMyService
{
private IMyDao myDao;
public MyServiceImpl()
{
}
public MyServiceImpl(IMyDao myDao)
{
this.myDao = myDao;
}
public String GetStuff()
{
return myDao.GetStuff();
}
}
}
The aspx page that calls the MyService:
private void Page_Load(object sender, System.EventArgs e)
{
logger.Debug("Loading page");
IApplicationContext ctx = ContextRegistry.GetContext();
IMyService myService = ctx.GetObject("myService") as IMyService;
String stuff = myService.GetStuff();
}
Every page request causes the logging message in the DAO method regardless if I have caching applied or not. I'm assuming I do not have this configured correctly.
Thanks in advance for any help!