Oliver Paulus
04-03-2007, 02:44 PM
Hello,
here is my configuration:
Dao.xml:
<?xml version="1.0"?>
<objects xmlns="http://www.springframework.net">
<object id="userDaoEntity" type="SpringSample.Dao.UserDao, SpringSample" singleton="true">
</object>
</objects>
Pages.xml:
<?xml version="1.0"?>
<objects xmlns="http://www.springframework.net">
<object type="UserList.aspx">
<property name="UserService" ref="userServiceEntity"/>
</object>
</objects>
Services-Aop.xml:
<?xml version="1.0"?>
<objects xmlns="http://www.springframework.net">
<object id="loggingAdvice" type="SpringSample.Service.AOP.LoggingAdvice, SpringSample"/>
<object id="settersAndAbsquatulateAdvisor" type="Spring.Aop.Support.RegularExpressionMethodPointcut Advisor, Spring.Aop">
<property name="advice">
<ref local="loggingAdvice"/>
</property>
<property name="patterns">
<list>
<value>.*</value>
</list>
</property>
</object>
<object id="ProxyCreator" type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoP roxyCreator, Spring.Aop"/>
</objects>
Services.xml:
<?xml version="1.0"?>
<objects xmlns="http://www.springframework.net">
<object id="userServiceEntity" type="SpringSample.Service.UserService, SpringSample" singleton="true">
<constructor-arg name="userDao" ref="userDaoEntity"/>
<property name="MyValue" value="100"/>
</object>
</objects>
Here is the code:
UserService:
public class UserService
{
private UserDao userDao;
private int myvalue;
public int MyValue
{
set
{
this.myvalue = value;
}
}
public UserService(UserDao userDao)
{
this.userDao = userDao;
}
public IList<User> getAll()
{
return this.userDao.getAll();
}
}
Page (UserList.aspx):
public partial class UserList : System.Web.UI.Page
{
private UserService userService;
public UserService UserService
{
get
{
return userService;
}
set
{
userService = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
userService.getAll();
}
}
The problem is the following: If I use the AOP configuration the injected UserService into UserList.aspx does has the private field UserDao == null. If I do not use the AOP configuration everything works expected. The same problem occurs with the MyValue Property of UserService: the injected entity of this type has MyValue == 0 if I use the AOP configuration. That is very confusing and seems to be a bug in Spring AOP with IoC container to me. It seems that singleton="true" does not work correctly too - because the setter of MyValue (e.g) will be called - I get it in Debug mode. But the entity injected into the ASPX page does not have the value in the field.
Here is the code for the Advice:
public class LoggingAdvice : IMethodInterceptor
{
public object Invoke(IMethodInvocation invocation)
{
Console.WriteLine("Before: invocation=[{0}]", invocation);
object rval = invocation.Proceed();
Console.WriteLine("Invocation returned");
return rval;
}
}
Any ideas?
here is my configuration:
Dao.xml:
<?xml version="1.0"?>
<objects xmlns="http://www.springframework.net">
<object id="userDaoEntity" type="SpringSample.Dao.UserDao, SpringSample" singleton="true">
</object>
</objects>
Pages.xml:
<?xml version="1.0"?>
<objects xmlns="http://www.springframework.net">
<object type="UserList.aspx">
<property name="UserService" ref="userServiceEntity"/>
</object>
</objects>
Services-Aop.xml:
<?xml version="1.0"?>
<objects xmlns="http://www.springframework.net">
<object id="loggingAdvice" type="SpringSample.Service.AOP.LoggingAdvice, SpringSample"/>
<object id="settersAndAbsquatulateAdvisor" type="Spring.Aop.Support.RegularExpressionMethodPointcut Advisor, Spring.Aop">
<property name="advice">
<ref local="loggingAdvice"/>
</property>
<property name="patterns">
<list>
<value>.*</value>
</list>
</property>
</object>
<object id="ProxyCreator" type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoP roxyCreator, Spring.Aop"/>
</objects>
Services.xml:
<?xml version="1.0"?>
<objects xmlns="http://www.springframework.net">
<object id="userServiceEntity" type="SpringSample.Service.UserService, SpringSample" singleton="true">
<constructor-arg name="userDao" ref="userDaoEntity"/>
<property name="MyValue" value="100"/>
</object>
</objects>
Here is the code:
UserService:
public class UserService
{
private UserDao userDao;
private int myvalue;
public int MyValue
{
set
{
this.myvalue = value;
}
}
public UserService(UserDao userDao)
{
this.userDao = userDao;
}
public IList<User> getAll()
{
return this.userDao.getAll();
}
}
Page (UserList.aspx):
public partial class UserList : System.Web.UI.Page
{
private UserService userService;
public UserService UserService
{
get
{
return userService;
}
set
{
userService = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
userService.getAll();
}
}
The problem is the following: If I use the AOP configuration the injected UserService into UserList.aspx does has the private field UserDao == null. If I do not use the AOP configuration everything works expected. The same problem occurs with the MyValue Property of UserService: the injected entity of this type has MyValue == 0 if I use the AOP configuration. That is very confusing and seems to be a bug in Spring AOP with IoC container to me. It seems that singleton="true" does not work correctly too - because the setter of MyValue (e.g) will be called - I get it in Debug mode. But the entity injected into the ASPX page does not have the value in the field.
Here is the code for the Advice:
public class LoggingAdvice : IMethodInterceptor
{
public object Invoke(IMethodInvocation invocation)
{
Console.WriteLine("Before: invocation=[{0}]", invocation);
object rval = invocation.Proceed();
Console.WriteLine("Invocation returned");
return rval;
}
}
Any ideas?