Solved

creating bean for BufferedWriter gets failed

Posted on 2008-10-05
1
532 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now