Solved

creating bean for BufferedWriter gets failed

Posted on 2008-10-05
1
535 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
1 Comment
 
LVL 59

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 6 43
Application.cfc - what is the order of events? 4 29
SHA2 certs for IIS AND Java? 2 80
login form jsp example 2 24
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

786 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