aspose file tools*
The moose likes Spring and the fly likes how do i solve this error caused due to problem in spring initiation on tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "how do i solve this error caused due to problem in spring initiation on tomcat" Watch "how do i solve this error caused due to problem in spring initiation on tomcat" New topic
Author

how do i solve this error caused due to problem in spring initiation on tomcat

Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ear.context' defined in ServletContext resource [/WEB-INF/bean.xml]:
Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]:
Constructor threw exception; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from class path resource [C:/Program Files/Apache Software Foundation/Tomcat 5.5/server/context.xml]; nested exception is java.io.FileNotFoundException:
class path resource [C:/Program Files/Apache Software Foundation/Tomcat 5.5/server/context.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

Well the exception is telling you that C:/Program Files/Apache Software Foundation/Tomcat 5.5/server/context.xml does not exist.


[How To Ask Questions][Read before you PM me]
Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
yes..
i need to have context.xml file in classpath right...??? i.e. in the deployed war file...
how do i do that....??
This is the hierarchy: /WEB-INF/
beans.xml
context.xml
web.xml
The web and beans.xml file is being accessed...why is it then giving me exception in context.xml
This is my beans.xml file:
<bean id="ear.context" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg index="0">
<list>
<value>/WEB-INF/context.xml</value>
</list>
</constructor-arg>
</bean>

It seems that constructor of ClassPathXmlApplicationContext cannot get context.xml file right..???
How do i solve this probelm??
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Well, put your context.xml in WEB-INF/classes and use classpath:context.xml in your bean definition.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Piyush Mangal wrote:Well, put your context.xml in WEB-INF/classes and use classpath:context.xml in your bean definition.


You can keep the file in the WEB-INF directory. Just use the prefix "http:" in where you load it.

so if it was in creation of ApplicationContext, you would have new ClassPathXmlApplicationContext("http:WEB-INF/context.xml")

as an example

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Mark Spritzler wrote:
Piyush Mangal wrote:Well, put your context.xml in WEB-INF/classes and use classpath:context.xml in your bean definition.


You can keep the file in the WEB-INF directory. Just use the prefix "http:" in where you load it.

so if it was in creation of ApplicationContext, you would have new ClassPathXmlApplicationContext("http:WEB-INF/context.xml")

as an example

Mark



Are you sure, ClassPathXmlApplicationContext("http:WEB-INF/context.xml") will work? I have never seen that before.
Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
Thanks!!!
It did work.

How do we call a function from a service.java file from bean.
I am done with constructor using <constructor-arg> tag and for setters <property> tags...
how a call a method?
For example:


in bean.xml file:
<bean id="login" class="loginService">
</bean>
This wont work....
How do we call a service method from bean and also hoe do we pass parameters to it?
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Try MethodInvokingFactoryBean.
Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
okk...
But i tried out the following code....its not working..
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Can you share what exception or error you are getting..
Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
The error clearly says that your loginDao does not have login(a,b,c); Could you please post your LoginDao (interface or class whatever is the case).
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

WOuldn't you just call getBean after the applicationContext has been created and then you call the method?

Or are you trying to figure out how you can hook into the lifecycle of an ApplicationContext and have a method run right after Spring has instantiated the object, like a bootstrap/init method.

With init method there are three ways

1) Annotate the method with @PostConstruct and add <context:annotation-config/> to your xml, remember you have to add the context namespace
2) In your xml bean definition add the attribute init-method="methodNameHere" to your <bean> tag
3) Have you class implement InitializingBean interface with the one method afterPropertiesSet().

Since you bean is already in xml I recommend #2. But the method cannot take any arguments, so your login_function does not match that. And I don't see any reason why you would want to call that method in the lifecycle callbacks. That looks to me like you want to call that method yourself in your code.

Mark
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Hi Sayaly,
Why do you want to invoke a method on a bean when application context is loaded?
Normally MethodInvokingFactoryBean is used to implement factory pattern.
As suggested by Mark, you should be calling loginService from your code somewhere.
Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
thanks Piyush and Mark...
M trying the same thing...
Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
My UI is andorid.
i am writing normal java files.
Say for example loginActivity:
to call servlet i use following code:



Now instead of calling Mainservlet i need to call the the service right???how do i do that??
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Hi,

You have an android application from where you capture companyId, username and password. All these details are passed on to MainServlet through post method.

Till this point everything looks fine. My question is how are you calling loginService through MainServlet and how does the code that you posted earlier fit into all of these?



Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
Let me explain you my goal first.

I am done with UI part using android and server coding using servlet and other java files.
Each activity calls the MainServlet file wherein i map the user request ti appropriate service file.
In MAinServlet;s post method i check the type:

loginService file has all the business logic
loginDAO file has code to query the database
loginValue file has all getters and setters.
THis all is working fine....

Without disturbing the UI , i am just trying to convert the server side to one which fits in springwork.
How do i do that??

This is the hierarchy: /WEB-INF/
beans.xml
context.xml
web.xml
The web and beans.xml file is being accessed...why is it then giving me exception in context.xml??

This is my beans.xml file:


and in context.xml file i have declared all my beans say <bean id="login" class"loginService"></bean> <bean id="menu" class"menuService"></bean>

From android side how do i call the login bean so as it trigger loginService class and how to i handle argument passing issue?
Should i remove the MainServlet file completely?M completely stuck.
Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
ohh..
defining contect.xml in WEB_INF/classes solved my issue of getting exception for class path.
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Hi,

As far as I understand , you have a client application which is on Android platform and a web application which this android application talks to.

So your android application has to go through HttpClient to connect to this web application. I would suggest to develop your web application using Spring MVC that will make

your job easier.
Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
yes..
My web app(WebProject under eclipse) follows the MVC achitecture.. (service class,DAO class and valueobject class)..
and my android app talks to web app using http post method successfully...

Then what i have done is..
I created a SpringProject under eclipse and added the same MVC architecture(service class,DAO class and valueobject class) to it along with bean.xml file..

How to i call a call a particular service.java file under spring project from android?

if its a standalone application then we can use:

Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
You can not directly call service.java from android application.
I would recommend to go through http://static.springsource.org/docs/Spring-MVC-step-by-step/ link. Spring MVC is a web framework by spring source based on MVC architecture which will suit your
requirement.
Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
Help me with foll error:



i have Mainservlet file in default package..
also mapped it in web.xml file and added <bean id="main" class="MainServlet"></bean> in beans.xml
Then why i get the above exception???
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Do you have your MainServlet in your WEB-INF/classes folder?

i have Mainservlet file in default package..
also mapped it in web.xml file and added <bean id="main" class="MainServlet"></bean> in beans.xml
Then why i get the above exception???


I am a bit confused why would you have a bean definiton for MainServlet.
Servlets are loaded and instantiated by web container, you should not instantiate MainServlet class yourself.
Sayaly Kolhe
Greenhorn

Joined: Mar 19, 2012
Posts: 15
Oh yes..
Mainservlet class i mapped in web.xml and removed it from bean file...
Got it working..

Thanks..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do i solve this error caused due to problem in spring initiation on tomcat
 
Similar Threads
Problem running tomcat - HTTP Status 404
setting tomcat5.5 server in eclipse
Tomcat 5.5 SEVERE: Error listenerStart
LOrdering Error wile starting Tomcat 7 server using Richfaces 4.1 and JSF 2.0
Spring MVC 3 and DWR 3 Integration Problem