• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 939
  • Last Modified:

XmlBeanFactory wont work

Ok this is making me madder than fish grease...I got everything set up including my prepared statements and such but the program wont get the datasource for crap. I know im doing it the right way. Esp since I asked this place and confirmed by browsing the internet that its the right way.For some odd reason the program just falls flat on its face when doing the xmlbeanfactory call. Code:

(this is in a initial method, not a main, that runs all the time)
XmlBeanFactory ac = new XmlBeanFactory(new ClassPathResource("Datasources.xml"));
                 System.out.println("here1 "+ac);
                 DataSource dataSource2 = (DataSource) ac.getBean("manifestTerminalDAO");
                 System.out.println("here2 "+dataSource2);
                setDataSource(dataSource2);

(simple spring jdbc datasourse setter)
public void setDataSource(DataSource ds) {
            dataSource = ds;
            this.jdbcTemplate = new JdbcTemplate(dataSource);
          }

(simple querycall for a list)
jdbcTemplate.queryForList(mManifestISeriesQueries.getAllSRT508FData(), PARAMS, Get_Manifest_Term_List);

(XML bean to get)
 <bean id="manifestTerminalDAO" class="com.maker.ground.manifest.dao.manifestTerminalDAO">
    <property name="dataSource" ref="DMMDataSource2" />

<bean id="DMMDataSource2" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName" value="jdbc/DMMDataSource" />
      <property name="environment">
            <props>
                  <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
                  <prop key="java.naming.provider.url">t3://localhost:7001</prop>
            </props>
      </property>
</bean>


see? simple enough right? Yet the Web program keeps stopping at the part to find the xml file.
The XML file is hosted in src/main/resources. the name of the xml file is Datasources.xml
0
Jtw549
Asked:
Jtw549
  • 17
  • 13
  • 3
  • +1
2 Solutions
 
for_yanCommented:



Did you see this post?
Semmes to be relevant or cloasely related.
http://www.coderanch.com/t/474047/Spring/Spring-cannot-find-file-classpath
0
 
objectsCommented:
> Yet the Web program keeps stopping at the part to find the xml file.

can you give some more details plaease
0
 
Jtw549Author Commented:
The program just stops at the line when trying to locate the xml file. I took it out and the program ran fine. But when I put it back in, it stop at that section. I tried a file inputstream and it gave me a java io exception saying the file could not be found when its clearly in my workspace. I even tried putting the path of the file into that section for the xmlbean and still nothing. I even moved the file to the same fold the code was doing the calling in and still nothing. I tried renaming the file and use other context extensions like Initialcontext or applicationcontext etc...and still nothing. I know it has to be that it cant find the file. I put system.out.prints before and after the xmlbean call. The first print goes off but after that it stops at the xml call. example:
Print(here)
xmlcall
Print(there)

I can usually fix stupid stuff like this. I have pretty much used up all my ideas besides remaking the xml file again....which I might just do.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
objectsCommented:
you sure its not throwing an exception?
0
 
for_yanCommented:
I'd still return to the situation where you just tried to  read this file as normal input sream and it tells you that file not
 fouind, but you think your path is in correct place.
This is the easiest thing to resolve in comparison with all the rest things which have all these additional classes and complications,
and also here you have obvious exception.
If you think you know the path and it believes the path is different you can try say to list files in its default location or
try first to go to some simple path and find the place where you have at least common understandting with the program.
And from there you'd find it.  That is the simple situation and once you resolve it perhaps you can figure out all what is happening with ClassPathResources, bean factories and other complex things.
0
 
CEHJCommented:
>>I tried a file inputstream and it gave me a java io exception saying the file could not be found when its clearly in my workspace.

Try that again (although it's deprecated) but this time give the absolute path starting from the root of the file system
0
 
Jtw549Author Commented:
I agree with the class pass which I made sure was right multiple time. I used both the builded path And the regular path before the build. Build path: /trunk2/target/dmm2/WEB-INF/classes/Datasources.xml ...Regular one: /trunk2/src/main/resources/Datasources.xml....I even put the xml file into my dao folder and tried /trunk2/src/main/java/com/fedex/ground/manifest/dao/Datasources.xml, yet nothing can be found.
0
 
Jtw549Author Commented:
So I tried this code to find out if indeed its just the finding of the file:

            java.net.URL fileURL = getClass().getClassLoader().getResource("Datasources.xml");
                   System.out.println("begin manifestTerminalList1");
                  UrlResource resource = new UrlResource(fileURL);
                   System.out.println("begin manifestTerminalList2");
                  BeanFactory factory = new XmlBeanFactory(resource);
                   System.out.println("begin manifestTerminalList3");
                  DataSource dataSource = (DataSource) factory.getBean("manifestTerminalDAO");
                   System.out.println("begin manifestTerminalList4");

The file gets found....But just like last time, once it hits the XMLBeanFactory part, it stops. Its as if the beanfactory doesn't want to take the file for some reason even though there is nothing wrong with the file.
0
 
CEHJCommented:
What's the value of 'fileURL'?
0
 
Jtw549Author Commented:
FileURL = zip:c:/bea/user_projects/domains/dmmdomain/servers/AdminServer/tmp/_WL_user/dmm2/qvchrg/war/WEB-INF/lib/_wl_cls_gen.jar!/Datasources.xml

Resource = URL [zip:c:/bea/user_projects/domains/dmmdomain/servers/AdminServer/tmp/_WL_user/dmm2/qvchrg/war/WEB-INF/lib/_wl_cls_gen.jar!/Datasources.xml]
0
 
CEHJCommented:
That doesn't look too good. You should really be getting a url in the context of your webapp. That's a url coming from an archive with a full path
0
 
CEHJCommented:
Try simply (if the file is in the classes directory)
java.net.URL url = getClass().getResource("/Datasources.xml");

Open in new window

0
 
Jtw549Author Commented:
for some reason that brings me back the same url as before. I tried putting the file in my src/main/webapp/WEB-INF and put src/main/webapp/WEB-INF/Datasources.xml and that comes back null.
0
 
CEHJCommented:
The simplest scenario is to have it the classes directory
0
 
Jtw549Author Commented:
also...so you have a better explanation of what the system looks like:
src
   main (under the src folder)
      java (under the main folder)
        com
           maker
               maker2
                   manifest
                         dao
                         dto
                         Iseries
                         more folders
     resources (under the main folder)
     Webapp (under the main folder)
0
 
for_yanCommented:

If I were you, given all this long mysterious history of this case,
 I would have started from the simplest situations - first can you read this flle  in the most basic way opening as
DataInputStream, then if that works - then when it works,
 go to FileSystemResource and then finally to you goal with ClassPathResource

Did you ever see this piece working?
You want first to get to situation when it works with whatever means, and after that gradually making it more
complex you'll see when it breaks and would hopefully undertand why.
When you start with most complex case with zips and classpathes it is much more difficult to know where is the problem
0
 
CEHJCommented:
You want to make sure that the resource file is getting deployed each time into classes
0
 
Jtw549Author Commented:
well Im gathering taht the file is getting deployed because I see it in the Web-inf folder of my Target build. which also has my property file hanging with it. I just did

 File file = new File("C:/Documents and Settings/#/workspace/trunk2/src/main/resources/Datasources.xml");
        System.out.println("begin manifestTerminalList3" +file);
        FileInputStream fin = null;
        try {
                  fin = new FileInputStream(file);
                  System.out.println("begin manifestTerminalList3" +fin);
            } catch (FileNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

and didnt get a FileNotFoundException. Or should this path be "trunk2/src/main/resources/Datasources.xml?
0
 
Jtw549Author Commented:
also wanted to say...when I put /Datasources.xml it sets off a file not found exception...Im probably just going to destroy my computer in rage and quit
0
 
CEHJCommented:
Well if it's successfully getting deployed into the resources directory then the following should work:


java.net.URL url = getClass().getResource("/resources/Datasources.xml");

Open in new window

0
 
objectsCommented:
you would use the following to get the path of a file in your web application

http://helpdesk.objects.com.au/java/how-to-get-the-path-of-a-file-in-a-web-application
0
 
Jtw549Author Commented:
Well based off of that I got, c:/bea/user_projects/domains/dmmdomain/servers/AdminServer/tmp/_WL_user/dmm2/qvchrg/war/WEB-INF/classes/Datasources.xml,

Which according to CEHJ I should not be getting. Thus the file seems to not be produced for the web but produced for archives. How would I change this so that I can get the right URL to be produced in order to have my web app use this file? Note: Im using weblogic if that matters.

The weird thing is that I have the property file thats hanging in the same folder with it. when I did the same servlet test I got Well based off of that I got, c:/bea/user_projects/domains/dmmdomain/servers/AdminServer/tmp/_WL_user/dmm2/qvchrg/war/WEB-INF/classes/CLM.properties, and that works fine in my webapp. Also, tried it for a DBConnection class.

The other weird part is when I did fileinputstream for DBConnection or CLM I got "The system could not find the path specified"
0
 
CEHJCommented:
>>Well based off of that I got ...

Are you sure you used the last code i gave you?
0
 
Jtw549Author Commented:
I used the get real path that object provided to get that answer and your code produced a null value. Thus making me think that the file is not being registered in the WAR file.

Full Stack trace from the  get real path put into fileinputstream:

 <[weblogic.servlet.internal.WebAppServletContext@12bae83 - appName: 'dmm2', name: 'dmm2.war', context-path: '/dmm2', spec-version: 'null'] Servlet failed with IOException
java.io.FileNotFoundException: C:\bea\user_projects\domains\dmmdomain\servers\AdminServer\tmp\_WL_user\dmm2\qvchrg\war\WEB-INF\classes\Datasources.xml (The system cannot find the file specified)
      at java.io.FileInputStream.open(Native Method)
      at java.io.FileInputStream.<init>(FileInputStream.java:106)
      at com.fedex.ground.manifest.servlet.manifestControllerServlet.doGet(manifestControllerServlet.java:51)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
      at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
      at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
      at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3498)
      at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
      at weblogic.security.service.SecurityManager.runAs(Unknown Source)
      at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
      at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
      at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
      at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
      at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
0
 
Jtw549Author Commented:
http://objectmix.com/weblogic/524679-getclassloader-getresourceasstream.html

according to the link above...It could be giving null due to weblogic
0
 
CEHJCommented:
>>... and your code produced a null value. Thus making me think that the file is not being registered in the WAR file.

Exactly. Can you please post the output of the following

jar tf yourwar.war

Open in new window

0
 
Jtw549Author Commented:

C:\Documents and Settings\818965\workspace\trunk2\target>jar tf dmm2.war
META-INF/
META-INF/MANIFEST.MF
css/
images/
js/
jsp/
style/
WEB-INF/
WEB-INF/classes/
WEB-INF/classes/com/
WEB-INF/classes/com/maker/
WEB-INF/classes/com/maker/maker2/
WEB-INF/classes/com/maker/maker2/manifest/
WEB-INF/classes/com/maker/maker2/manifest/dao/
WEB-INF/classes/com/maker/maker2/manifest/dto/
WEB-INF/classes/com/maker/maker2/manifest/dto/Terminal/
WEB-INF/classes/com/maker/maker2/manifest/ISeries/
WEB-INF/classes/com/maker/maker2/manifest/log/
WEB-INF/classes/com/maker/maker2/manifest/model/
WEB-INF/classes/com/maker/maker2/manifest/model/beans/
WEB-INF/classes/com/maker/maker2/manifest/service/
WEB-INF/classes/com/maker/maker2/manifest/servlet/
WEB-INF/classes/com/maker/maker2/manifest/utilities/
WEB-INF/classes/com/maker/maker2/manifest/vo/
WEB-INF/classes/com/maker/maker2/util/
WEB-INF/classes/com/maker/maker2/util/wsso/
WEB-INF/classes/com/maker/maker2/util/wsso/vo/
WEB-INF/lib/
css/manifest.css
css/scroll.css
images/calendar.jpg
images/checkallbutton.jpg
images/maker_logo.jpg
images/green_line.gif
images/maker2_maker_logo.gif
images/line.gif
images/loading_animation_liferay.gif
images/logo_long.jpg
images/manifest_hdr.gif
images/move_dn.jpg
images/move_up.jpg
images/next.gif
images/prev.gif
images/purple_line.gif
images/Thumbs.db
images/vbanner.jpg
images/x_out.jpg
js/calendarDateInput.js
js/index.js
js/print_selections.js
jsp/banner.jsp
jsp/head.jsp
jsp/index.jsp
jsp/indexold.jsp
jsp/manifestContractorSelections.jsp
jsp/ManifestDisplayExpManifest.jsp
jsp/ManifestDisplayPDFError.jsp
jsp/manifestError.jsp
jsp/manifestFooter.jsp
jsp/manifestFooterx.jsp
jsp/manifestHeader.jsp
jsp/manifestLayoutSpecifications.jsp
jsp/manifestMain.jsp
jsp/manifestNavigation.jsp
jsp/manifestNavigationold.jsp
jsp/manifestPrintByBelt.jsp
jsp/manifestPrinterSelection.jsp
jsp/manifestPrintMenu.jsp
jsp/manifestPrintMenujr.jsp
jsp/manifestSetTerminalPrinterDefaults.jsp
jsp/manifestSetUserDefaultPrinter.jsp
jsp/welcome.jsp
ManifestCypressQueryServlet.ini
style/ManifestCypressQueryServlet.css
Test.html
WEB-INF/classes/CLM.properties
WEB-INF/classes/com/maker/maker2/manifest/dao/DbConnection.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestContractorDAO.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestDaoBase.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestPrintDAO.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestPrinterLocationDAO.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestQuerySearchResultDAO.class

WEB-INF/classes/com/maker/maker2/manifest/dao/manifestTerminalDAO$1.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestTerminalDAO$10.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestTerminalDAO$2.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestTerminalDAO$3.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestTerminalDAO$4.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestTerminalDAO$5.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestTerminalDAO$6.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestTerminalDAO$7.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestTerminalDAO$8.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestTerminalDAO$9.class
WEB-INF/classes/com/maker/maker2/manifest/dao/manifestTerminalDAO.class
WEB-INF/classes/com/maker/maker2/manifest/dao/TerminalInfoDAO.class
WEB-INF/classes/com/maker/maker2/manifest/dto/Terminal/TerminalInfo.class
WEB-INF/classes/com/maker/maker2/manifest/ISeries/manifestISeriesInterface.class

WEB-INF/classes/com/maker/maker2/manifest/log/AppLogger.class
WEB-INF/classes/com/maker/maker2/manifest/manifestPrinterLocationList.class
WEB-INF/classes/com/maker/maker2/manifest/manifestPrintList.class
WEB-INF/classes/com/maker/maker2/manifest/manifestQuerySearchList.class
WEB-INF/classes/com/maker/maker2/manifest/manifestTerminalList.class
WEB-INF/classes/com/maker/maker2/manifest/model/beans/AwadContractorBean.class
WEB-INF/classes/com/maker/maker2/manifest/model/beans/FacilityBean.class
WEB-INF/classes/com/maker/maker2/manifest/model/beans/PrinterListBean.class
WEB-INF/classes/com/maker/maker2/manifest/model/beans/RegionBean.class
WEB-INF/classes/com/maker/maker2/manifest/model/beans/TerminalBean.class
WEB-INF/classes/com/maker/maker2/manifest/model/beans/TerminalListBean.class
WEB-INF/classes/com/maker/maker2/manifest/model/ManifestConstants.class
WEB-INF/classes/com/maker/maker2/manifest/model/PropertiesConstants.class
WEB-INF/classes/com/maker/maker2/manifest/service/Persistor.class
WEB-INF/classes/com/maker/maker2/manifest/service/PersistorImpl.class
WEB-INF/classes/com/maker/maker2/manifest/servlet/baseServlet.class
WEB-INF/classes/com/maker/maker2/manifest/servlet/manifestControllerServlet.clas
s
WEB-INF/classes/com/maker/maker2/manifest/servlet/ManifestCypressQueryServlet.cl
ass
WEB-INF/classes/com/maker/maker2/manifest/servlet/manifestServlet.class
WEB-INF/classes/com/maker/maker2/manifest/servlet/SystemDate.class
WEB-INF/classes/com/maker/maker2/manifest/utilities/ContractorComparator.class
WEB-INF/classes/com/maker/maker2/manifest/utilities/DepartmentNo.class
WEB-INF/classes/com/maker/maker2/manifest/utilities/FileIo.class
WEB-INF/classes/com/maker/maker2/manifest/utilities/ManifestConstants.class
WEB-INF/classes/com/maker/maker2/manifest/utilities/manifestISeriesQueries.class

WEB-INF/classes/com/maker/maker2/manifest/utilities/StringManipulations.class
WEB-INF/classes/com/maker/maker2/manifest/utilities/Util.class
WEB-INF/classes/com/maker/maker2/manifest/vo/manifestContractorVO.class
WEB-INF/classes/com/maker/maker2/manifest/vo/manifestPrinterLocationVO.class
WEB-INF/classes/com/maker/maker2/manifest/vo/manifestPrintVO.class
WEB-INF/classes/com/maker/maker2/manifest/vo/manifestQuerySearchResultVO.class
WEB-INF/classes/com/maker/maker2/manifest/vo/manifestTerminalPrinterDefaultsVO.c
lass
WEB-INF/classes/com/maker/maker2/manifest/vo/manifestTerminalVO.class
WEB-INF/classes/com/maker/maker2/util/wsso/vo/DepartmentNo.class
WEB-INF/classes/Datasources.xml
WEB-INF/lib/jt400-4.8.jar
WEB-INF/lib/log4j-1.2.8.jar
WEB-INF/lib/spring-2.5.5.jar
WEB-INF/web.xml
META-INF/maven/
META-INF/maven/com.maker.maker2/
META-INF/maven/com.maker.maker2/dmm2/
META-INF/maven/com.maker.maker2/dmm2/pom.xml
META-INF/maven/com.maker.maker2/dmm2/pom.properties
0
 
Jtw549Author Commented:
WEB-INF/classes/Datasources.xml <--- There it goes :(
0
 
CEHJCommented:
>> There it goes :(

Well that's not where you really want it. Your plan of /resources is best. You need to ensure that that directory is being treated the same as /images when it comes to deployment (as it's absent at the moment)
0
 
CEHJCommented:
Given your listing, the following should work:
java.net.URL url = getClass().getResource("/images/next.gif");

Open in new window

0
 
Jtw549Author Commented:
And given that code Id say the same thing but for some reason it comes back null.....Im about to just Delete everything and start over...I got another project from our repository and stuck a xml in there and it does the same thing. At this point I will probably try it on another computer to see if its a environment issue or weblogic. Also, the Absolute path for the xml file is C:\bea\user_projects\domains\dmmdomains\Datasources.xml, which is stored in the weblogic area where the war file is being stored.
0
 
CEHJCommented:
There's got to a way to get it working properly. It shouldn't be necessary to be delving into the file system
0
 
Jtw549Author Commented:
I agree...Its just sad that no one at work wants to help me on the issue...esp the people that know the system the best. Just by putting a xml file into a resource folder then building should give the file a url. Esp since its associated under the WEB-INF folder. There is no way weblogic should interfere with how the file is being handled in the WAR.  This issue is very VERY unusual and I will never forget it if I figure out the solution.
0
 
Jtw549Author Commented:
Ya...I think its my environment....This other guy tried it out just by putting the file into the resource folder and it Bloody worked....That makes me mad.....very mad...Spent 3 days on it and its my freaking computer. This makes me feel ultra useless.
0
 
Jtw549Author Commented:
Their solutions actually work its just my environment is total horse caca
0
 
CEHJCommented:
>>This makes me feel ultra useless.

I know how you feel. Often you can comfort yourself with the realization that the fault is with someone else's software ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 17
  • 13
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now