Solved

creating bean for BufferedWriter gets failed

Posted on 2008-10-05
1
539 Views
Last Modified: 2013-11-23
I am trying to create bufferedWriter like as shown below in my cpring config file

<bean name="fileWriter" class="java.io.FileWriter">
                <constructor-arg index="0">
                        <value>/home/translator3.3/src/resources/sampledata/cigna/welcomecallrubric.txt</value>
                </constructor-arg>
                <constructor-arg index="1">
                        <value>false</value>
                </constructor-arg>
        </bean>
      <bean name="bufferedWriter" class="java.io.BufferedWriter">
                <constructor-arg index="1">
                        <ref bean="fileWriter" />
                </constructor-arg>
        </bean>



I am havin error

Cannot resolve reference to bean 'bufferedWriter' while setting bean property 'writer'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bufferedWriter' defined in file [/home/rchilka/c4ctranslator3.3/src/resources/config/cigna/welcomecallrubric.xml]: Cannot resolve reference to bean 'fileWriter' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileWriter' defined in file [/home//src/resources/config/comecall.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.io.FileWriter]: Constructor threw exception; nested exception is java.io.FileNotFoundException: /home/rchilka/c4ctranslator3.3/src/resources/sampledata/cigna/welcomecallrubric.txt (No such file or directory)
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'DocumentBuilderFactory' defined in file [/home/rchilka/c4ctranslator3.3/src/resources/config/cigna/welcomecallrubric.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?


Can anybody help in solving above?
0
Comment
Question by:cutie_smily
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 22645855
AFAIK, you can't use java.io.FileWriter and java.io.BufferedWriter in that manner as they are not beans which have getter/setter methods.  They are for file I/O and require instantiation with a file name and are typically wrapped in try/catch blocks or methods that throw I/O exceptions like FileNotFoundException.

Try just putting that code in a straight code block instead of bean tag.

http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileWriter.html
http://java.sun.com/j2se/1.4.2/docs/api/java/io/BufferedWriter.html

Regards,
Kevin
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question