Solved

creating bean for BufferedWriter gets failed

Posted on 2008-10-05
1
537 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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.

820 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