Results 1 to 3 of 3

Thread: Newbie: NotWritablePropertyException

  1. #1
    Join Date
    Sep 2009
    Posts
    4

    Default Newbie: NotWritablePropertyException

    Hi,

    I'm just getting up to speed with integrating Spring into a Struts 2 Web Application I'm developing. I've created an applicationContext.xml with two beans. When I try to deploy my web project, I am receiving the NotWritablePropertyException: Invalid property 'securityManager' of bean class [com.test.interceptor.LoginInterceptor]: Bean property 'securityManager' is not writable or
    has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

    My applicationContext.xml contains the following:

    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <!DOCTYPE beans PUBLIC 
    	"-//SPRING//DTD BEAN//EN" 
    	"http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    	<bean id="loginInterceptor" singleton="true" class="com.test.interceptor.LoginInterceptor">
        	<property name="securityManager"><ref local="securityManager" /></property>
    	</bean>
    	
    	<bean id="securityManager" singleton="true" class="com.test.security.impl.SecurityManagerImpl"/>
    </beans>
    My code for my SecurityManager Interface is:

    Code:
    package com.test.security;
    
    public interface SecurityManager {
    	
    	public User login (String name, String pswd);
    
    }
    My SecurityManager Implementation looks like the following:

    Code:
    package com.test.security.impl;
    
    import com.test.security.SecurityManager;
    import com.test.security.User;
    
    public class SecurityManagerImpl implements SecurityManager {
    	
    	private SecurityManagerImpl securityManager = null;
    	
    	public void setSecurityManager(SecurityManagerImpl securityManager)
    	{
    		this.securityManager = securityManager;
    	}
    
    	public User login(String name, String pswd) {
    		
    		//TODO: delegate to user lookup class to obtain user credentials
    		
    		return new User(){};
    	}
    
    }
    I would really appreciate some advice as to what I seem to be missing in my configuration as I can't seem to find any obvious typos that would account for this?

    Thanks in advance.

  2. #2
    Join Date
    Apr 2008
    Location
    Seville, Spain
    Posts
    132

    Default

    Hi, you need a setSecurityManager method in com.test.interceptor.LoginInterceptor, not in SecurityManagerImpl

    cheers

  3. #3
    Join Date
    Sep 2009
    Posts
    4

    Default

    Yep, I figured it out just after I posted. Just assumed I needed to put the singleton reference in the actual implementation class, but it makes good sense to place it in the class that is dependent upon this class.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •