0

i'm developing a web application using spring 3. i'm using tomcat 6 as the web container.

in my web.xml file i bound the file named applicationContext.xml as the spring definition file.

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

from inside the applicationContext.xml file i'm trying to initialize a array list variable using the spring bean definition. i'm following the below configurations.. (im using jidea)

<bean id="registationController" class="com.test.RegistrationController">
    <property name="registrationService" ref="registrationService"/>
    <property name="validUrlsList" ref="myList"/>
</bean>

<util:list id="myList" value-type="java.lang.String">
    <value>10.1.200.104</value>
    <value>10.1.200.205</value>
</util:list>

i have loaded the

xmlns:util="http://www.springframework.org/schema/util"

namespace, and in RegistrationController.java class i have generated the getter and setter for the validUrlsList variable, jidea shows that my definitions are correct and i have properyly bound my vaiable to the bean definition. but when i try out the code it doesn't initialize the validUrlList variable? it's giving a null value? any thing i'm doing wrong here? any suggestions to sort this out?

java code is as follows.,,

private ArrayList validUrlsList;    
public void setValidUrlsList(ArrayList validUrlsList) {
    this.validUrlsList = validUrlsList;
}

public ArrayList getValidUrlsList() {
    return validUrlsList;
}

then i call the method getRemoteIp by just passing the variable as follows.

if (getRemoteIP(req, validUrlsList)) {

-- Regards,Rangana

3
  • Show us how you're trying out the code. And show us the code of RegistrationController. Oh, and the name of your IDE is IntelliJ IDEA. Not jidea. Commented May 19, 2013 at 9:53
  • modified the question to add the java code? i haven't used XmlBeanFactory, thought it will be initialized as it loads? Commented May 19, 2013 at 10:08
  • How do you know that the list Spring constructs is an ArrayList? How could it call your setter if the list it constructs from your XML is a LinkedList, or an unmodifiable list? Code against interfaces. Use List<String> and not ArrayList<String>. Commented May 19, 2013 at 10:12

1 Answer 1

1

util:list is creating java.util.List instance, it is not said to create java.util.ArrayList.

You should change your declaration from

private ArrayList validUrlsList;   

to

private List validUrlsList;   

(and setter and getter as well).

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

1 Comment

by changing to java.util.List worked, but i had to make the variable static... private static List validUrlsList; only then i was able to get the list properly. Thanks for the great support. :)

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.