简体   繁体   中英

Spring MVC send properties via controller to a xml declared bean

I wanted to know if I can pass a property to a bean I declared on a xml configuration file (for example on the applicationContext.xml):

<bean id="captchaVerifierFilter" class="org.abc.filter.CaptchaVerifierFilter" 
            p:useProxy="false" 
            p:proxyPort="" 
            p:proxyHost=""
            p:failureUrl="/abc/main/loginfailed"
            p:captchaCaptureFilter-ref="captchaCaptureFilter"
/>

I want to use the captchaVerifierFilter bean to test if a captcha is valid or not. Then I can set the failureUrl property to url "add-record" and redirect to that jsp.

How can I send a property (like failureUrl for example) through a controller. Is this possible? What should I code on the controller if it's possible?

Any idea? Thank you very much!

I think you should define both the success and the failure url as properties in your configuration and then let the filter decide which way to go.

You can change the properties of the bean if you make it accessible (by making it public or with a setter) but that is probably not want you want since it changes the property for the single bean instance in the application context which is used by several threads concurrently.

Best regards

Hacim

By default the beans in the context are in singleton scope. So when you set the value for the property failureUrl in one controller, another controller will also see this new value when it gets the bean from the context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM