-1

I have the following Bean which I would like to have autowired in another class:

@Scope("job")
@Component
public class PublicCompanyHolder {

private List<File> publicCompanyList;

public List<File> getPublicCompanyList() {
return publicCompanyList;
}

public void setPublicCompanyList(List<File> publicCompanyList) {
this.publicCompanyList = publicCompanyList;
}

}

My Spring config looks like :

 <bean id="publicCompanyHolder" class="com.sample.bean.PublicCompanyHolder" >   
        <property name="publicCompanyList" ref="publicCompanyList" />
     </bean>
      <bean id="publicCompanyList" class="java.util.List" />

Is this the right way to do it.In another class by simply saying:

@Autowired
    private PublicCompanyHolder publicCompanyHolder;

I would like to use the class.Please let me know.

user5053360
  • 279
  • 2
  • 14
  • What's wrong with what you have? What happened when you tried it? – Sotirios Delimanolis Aug 14 '15 at 00:00
  • I was getting the following error - Error creating bean with name 'publicCompanyHolder' defined in class path resource [applicationBatchContext.xml]: Cannot resolve reference to bean 'publicCompanyList' while setting bean property 'publicCompanyList'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'publicCompanyList' defined in class path resource [applicationBatchContext.xml]: . – user5053360 Aug 14 '15 at 13:51
  • I was able to fix this.There were two issues.One was a class needed to be used instead of an interface(List).Second,scanning of the packages needed to be enabled in the spring config file. – user5053360 Aug 15 '15 at 10:46

1 Answers1

-1

java.util.List is the interface. You need to give implementation.

<bean id="publicCompanyList" class="java.util.List" />

You can do like below

How to define a List bean in Spring?

Community
  • 1
  • 1
Sumit Gupta
  • 286
  • 1
  • 15