Results 1 to 5 of 5

Thread: How use an innerbean for the prototypeBeanName property

  1. #1
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Question How use an innerbean for the prototypeBeanName property

    Hello Members

    I have the follow and work fine

    Code:
    ...
    <property name="lineMapper" >
    	<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper" >
     		<property name="lineTokenizer" >
                            ...
    	      	</property>
    		<property name="fieldSetMapper" >
    		        <bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper" >
    		  		<property name="prototypeBeanName" value="tasaCastigoInteres"/>		  			
    		  	</bean>
    		</property>
    	</bean>			
    </property>
    ...
    
    <bean id="tasaCastigoInteres" 
     	 class="com.manuel.jordan.domain.TasaCastigoInteres" 
         scope="prototype" 	      
     	      />
    How I can put the bean tasaCastigoInteres how an inner bean for the prototypeBeanName property? Since this property expects a String value?

    Thanks in advanced
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    You aren't ... You are directly setting the value not a reference. So basically your bean 'tasaCastigoInteres' doesn't do anything...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    Hi Marten

    You aren't ... You are directly setting the value not a reference.
    Yes, I know

    This property (prototypeBeanName) must work with a value and not with a ref. Otherwise I get an exception.

    I mean, If I use

    Code:
    ...
    <property name="lineMapper" >
    	<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper" >
     		<property name="lineTokenizer" >
                            ...
    	      	</property>
    		<property name="fieldSetMapper" >
    		        <bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper" >
    		  		<property name="prototypeBeanName" ref="tasaCastigoInteres"/>		  			
    		  	</bean>
    		</property>
    	</bean>			
    </property>
    ...
    
    <bean id="tasaCastigoInteres" 
     	 class="com.manuel.jordan.domain.TasaCastigoInteres" 
         scope="prototype" 	      
     	      />
    I get

    Code:
    Caused by: java.lang.IllegalStateException: 
    Cannot convert value of type 
    [com.manuel.jordan.domain.TasaCastigoInteres] to required type [java.lang.String] for property 'prototypeBeanName': 
    no matching editors or conversion strategy found
    	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:241)
    I thought that could exists a way to turn around this with an inner bean like the follow.

    Code:
    <property name="fieldSetMapper" >
    	<bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper" >
    		<property name="prototypeBeanName" >
    			<bean  
     	   			class="com.manuel.jordan.domain.TasaCastigoInteres" 
     	   			scope="prototype"
     	   		/>
    		</property>		  			
    	</bean>
    </property>
    But I get the same exception

    So basically your bean 'tasaCastigoInteres' doesn't do anything...
    No really

    If I do

    Code:
    ...
    <property name="lineMapper" >
    	<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper" >
     		<property name="lineTokenizer" >
                            ...
    	      	</property>
    		<property name="fieldSetMapper" >
    		        <bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper" >
    		  		<property name="prototypeBeanName" ref="tasaCastigoInteres"/>		  			
    		  	</bean>
    		</property>
    	</bean>			
    </property>
    ...
    <!--
    <bean id="tasaCastigoInteres" 
     	 class="com.manuel.jordan.domain.TasaCastigoInteres" 
         scope="prototype" 	      
    />
    -->
    I get

    Code:
    Caused by: 
    org.springframework.beans.factory.NoSuchBeanDefinitionException: 
    No bean named 'tasaCastigoInteres' is defined
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:553)
    I hope you see now my point.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    All the configurations you posted, which lead to an exception, are at runtime the same configurations.

    But I get the same exception

    No really
    Your sample posted yes it doesn't do anything because it is a value... If you change it to a ref it doesn't work no matter if you use an inner bean or not it will never be a string it is a bean of a certain type...

    I hope you see now my point.
    I still don't see your point or what you want to achieve. The property is of a type string and can only be set to a string nothing more, nothing less. YOur bean, regardless if it is defined of a ref or inner-bean, remains something else as a String it will never become a String.

    If you want the property to change on each execution make it step-scoped and use late binding (as explained in the spring batch reference guide).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    366

    Default

    THe issue here is due to the prototype scope. Using ref implies that it's a reference to a bean, a single instance of a class. In this case, that is not what that property is. The BeanWrapperFieldSetMapper will create a new instance every time the bean is needed. You'll have to look in the core Spring docs to see if there is a way to define a prototype bean inline like you can a regular bean (I would suspect you can't).
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •