3

Using spring on a webservice I have this code:

@RequestMapping(value = "/testOperation", method = GET)     
public String testOperation() throws Exception 
{                   
    ts.setName("First Value");
    ts.name = "Second Value";
    return ts.getName() + " and " + ts.name;                
}

The response received is "First Value and Second Value". I do not understand why is not "Second Value and Second Value". ts is a request scope injected variable. The code is:

@Component
@Scope(value=WebApplicationContext.SCOPE_REQUEST, proxyMode=ScopedProxyMode.TARGET_CLASS)
public class TS implements Serializable{        
    public String name;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

I do not understand this behavior

1 Answer 1

1

As TS is configured to be request scoped obviously spring creates proxy for it. So setName and getName invocations are redirected to TS instance that is created for every request. But direct field reference can't be proxied and it affects only instance injected to controller.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.