Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Spring for server side code + webservice

  1. #11
    Join Date
    Mar 2012
    Posts
    17

    Default

    Yes i have deployed it in war file..

    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.ClassPa thXmlApplicationContext">
    <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??

  2. #12
    Join Date
    May 2011
    Location
    Madrid (Spain)
    Posts
    101

    Default

    Hi, do you have in your web.xml this?:

    Code:
    	<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/context.xml</param-value>
    	</context-param>

  3. #13
    Join Date
    Mar 2012
    Posts
    17

    Default xml file hierarchy unser WEB-INF folder

    My web.xml file:
    Code:
    <web-app id="WebApp">
    	<display-name>Project</display-name>
    
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/bean.xml</param-value>
    	</context-param>	
    
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    </web-app>
    my bean.xml file:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
    						http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    	<bean id="ear.context" class="org.springframework.context.support.ClassPathXmlApplicationContext">
    		<constructor-arg>
    		<value>/WEB-INF/context.xml</value>
    		</constructor-arg>
    	</bean>
    </beans>
    My context.xml file:
    Code:
    <bean id="login" class="Trial.Controller">
    	</bean>
    The Controller class contains code to update database...


    Error:
    Code:
    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 [WebContent/WEB-INF/acontext.xml]; nested exception is java.io.FileNotFoundException: class path resource [WebContent/WEB-INF/acontext.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)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

  4. #14
    Join Date
    May 2011
    Location
    Madrid (Spain)
    Posts
    101

    Default

    OK, instead of referencing context.xml in bean.xml, you should define it in web.xml :

    Code:
    <servlet>
      <servlet-name>appServlet</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/context.xml</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
    </servlet>
    If you'd like to see a complete example, see this.

  5. #15
    Join Date
    Mar 2012
    Posts
    17

    Default

    hey thanks..
    i saw the complete example and tried to map my problem...
    i defined context.xml in web.xml file..
    but it is still giving the same error...

    from web.xml the bean.xml file is loaded properly i guess...
    from the bean.xml file when passes constructor argument(context.xml) to ClassPathXmlApplicationContext its throwing error right??
    its there in WEB-INF folder..i matched the spellling too...
    Please help with the error..

  6. #16
    Join Date
    May 2011
    Location
    Madrid (Spain)
    Posts
    101

    Default

    Why do you define this?

    Code:
    	<bean id="ear.context" class="org.springframework.context.support.ClassPathXmlApplicationContext">
    		<constructor-arg>
    		<value>/WEB-INF/context.xml</value>
    		</constructor-arg>
    	</bean>
    You can define directly your beans in bean.xml, for example: https://github.com/SpringSource/spri...et-context.xml

  7. #17
    Join Date
    Mar 2012
    Posts
    17

    Default

    In github example...it is a complete springproject with all the views defined in WebContent itself.

    I am done with UI part for my project using android and server coding using servlet and other java files.
    Without disturbing the UI , i am just trying to convert the server side to one which fits in springwork.

  8. #18
    Join Date
    Mar 2012
    Posts
    17

    Default

    hey...
    <bean id="ear.context" class="org.springframework.context.support.ClassPa thXmlApplicationContext">
    <constructor-arg>
    <value>file:C:\Users\User\workspace\WebProjectTria l\WebContent\WEB-INF\context.xml</value>
    </constructor-arg>
    </bean>

    adding the entire path..its working fine.... but is it the correct way??
    anyways atleast i got something working...

    How do we set the classpath of any WebProject...??
    http://static.springsource.org/sprin...resources.html

  9. #19
    Join Date
    May 2011
    Location
    Madrid (Spain)
    Posts
    101

    Default

    No, it isn't the correct way, you can define your trial.Controller in bean.xml, you should learn the basic concepts first, see again the link:

    courses.coreservlets.com/Course-Materials/pdf/spring/basics/03-Spring-in-Web-Apps.pdf

    you'll see what you need (applicationContext.xml)

  10. #20
    Join Date
    Mar 2012
    Posts
    10

    Default

    You can use Spring REST to create a Restful webservice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •