Results 1 to 8 of 8

Thread: Error with ApplicationContext

  1. #1
    Join Date
    Jan 2008
    Posts
    18

    Default Error with ApplicationContext

    Hi!
    I have created a file applicationContext-hibernate.xml in WEB-INF. In web.xml I have added the next code :

    Code:
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext-hibernate.xml</param-value>
      </context-param>
      <listener>
         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
    Then, from Controller I have added the next code
    Code:
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-hibernate.xml");
    and it fails. The error is the next :

    Code:
    SEVERE: Servlet.service() for servlet CREEAapp threw exception
    java.io.FileNotFoundException: class path resource [applicationContext-hibernate.xml] cannot be opened because it does not exist
    	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:142)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:307)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:158)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:184)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:112)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:97)
    	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:411)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:338)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
    	at creea.spring.mvc.controladores.login.LoginController.handleRequest(LoginController.java:56)
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    	at java.lang.Thread.run(Unknown Source)
    What does it happen?
    Thanks

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    WHY o WHY do you try to load the application context AGAIN?!
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jan 2008
    Posts
    18

    Default

    I'm trying to use spring+ hibernate, I don't know it how I should. Can you explain me how it works, please?

    In applicationContext-hibernate.xml I have added the next code (

    Code:
    <beans>
    	<!-- DataSource (MySQL) -->
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<property name="url" value="jdbc:mysql://localhost/CREEA" />
    		<property name="username" value="root" />
    		<property name="password" value="1234" />
    	</bean>
    <!-- Hibernate SessionFactory -->
    	<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="mappingResources">
    			<list>
    				<value>Usuario.hbm.xml</value>
    			</list>
    		</property>
    		<property name="hibernateProperties">
    			<value>
    			   hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
    			   hibernate.hbm2ddl.auto=update
    			</value>
    		</property>
    	</bean>
    
    	<!-- Definiciones capa DAO -->
    	<bean id="usuarioDao" class="creea.spring.hibernate.dao.imp.UsuarioHibernate">
    		<property name="sessionFactory" ref="mySessionFactory" />
    	</bean>
    
    </beans>
    and I want to use it from the controller with the code

    Code:
    	     	ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-hibernate.xml");
    	        UsuarioDao usersdao = (UsuarioDao)ctx.getBean("usuarioDao");
    	        boolean bPasswordCorrecto = usersdao.existeUser(usuUsuario) ;
    I need than someone explain me how I can use spring + hibernate correctly.
    Thanks

  4. #4
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    Go through the excellent Spring MVC Step-by-Step tutorial on the Spring site. It should point you in the right direction.
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  5. #5
    Join Date
    Jan 2008
    Posts
    18

    Default

    Is there another tutorial with spring and Hibernate?

  6. #6
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    Quote Originally Posted by Sarah80 View Post
    Is there another tutorial with spring and Hibernate?
    Not that I've ever seen, but the one I referenced should be able to answer the question you asked about how to set up Spring MVC. The "Pet Clinic" sample application that comes with the full Spring distribution includes some Hibernate-related bits, but it's just static code, there's not an accompanying tutorial.
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  7. #7
    Join Date
    Apr 2005
    Location
    Finland
    Posts
    314

    Default

    Quote Originally Posted by Sarah80 View Post
    Is there another tutorial with spring and Hibernate?
    See also the examples that ships with the Spring distribution (Pet Clinic etc). Even this is not a tutorial, it gives you ideas how things should (or can) be done. The application is quite simple.
    if a trainstation is where the train stops, what's a workstation...

  8. #8
    Join Date
    Jan 2008
    Posts
    18

    Default

    Yesterday, I read the tutorial and I now my application works. Thanks !!

Posting Permissions

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