Announcement Announcement Module
Collapse
No announcement yet.
Singleton instantiation problem/exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Singleton instantiation problem/exception

    Hi all.

    This exception is thrown:
    Code:
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'javaRoom' defined in ServletContext resource [/WEB-INF/chat-servlet.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [int]: Did you specify the correct bean references as generic constructor arguments?
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createArgumentArray(AbstractAutowireCapableBeanFactory.java:622)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:495)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:306)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:260)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:221)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
    	at .... (blah-blah-blah)

    The (hopefully) relevant setup:
    Code:
    <bean id="javaRoom" 
    		class="com.objectnova.kantorn.simplechat.domain.ChatRoom" 
    		singleton="true">
    		<constructor-arg><value>20</value></constructor-arg>
    	</bean>
    Source:
    Code:
    public class ChatRoom implements IChatRoom &#123;
    
    	private Collection participants;
    
    	private LinkedList posts;
    	private int maxPosts = 0;
    	
    	public ChatRoom&#40;int posts&#41;&#123;
    		this.participants = new Vector&#40;&#41;;
    		this.posts = new LinkedList&#40;&#41;;
    		this.maxPosts = posts;
    	&#125;
    .
    .
    .
    &#125;
    My question is: how could BeanFactory not understand this simple constructor?
    What am I missing, ye Wizards of Spring?

  • #2
    Try using:
    Code:
          <constructor-arg index="0"><value>20</value></constructor-arg>
    or
    Code:
          <constructor-arg type="int"><value>20</value></constructor-arg>

    Comment


    • #3
      Code:
            <constructor-arg index="0"><value>20</value></constructor-arg>
      worked just fine.

      Thank you!

      Comment

      Working...
      X