1

I know configuring OSIVF is a common pain point. I've read all the pages I could find over that last couple of days, but nothing seems to get me past this issue. I have succeeded in getting myself confused, tho. I'm trying to keep this config really simple as the web app is pretty straightforward. Well, here's the error:

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:90)
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:190)

Here's the web.xml:

<web-app version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Test MVC Application</display-name>

    <servlet>
        <servlet-name>onepic</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>onepic</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>hibernateFilter</filter-name>
        <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
        <init-param>
            <param-name>sessionFactoryBeanName</param-name>
            <param-value>sessionFactory</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>hibernateFilter</filter-name>
        <url-pattern>/</url-pattern>
    </filter-mapping>



    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


</web-app>

Finally, here's some bits from onepic-servlet.xml:

<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:3306/onePic?characterEncoding=UTF-8"/>
    <property name="username" value="onePic"/>
    <property name="password" value="onePic"/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="datasource" />
    <property name="packagesToScan" value="com.sandofamily.onePic"/>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect"> org.hibernate.dialect.H2Dialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

<tx:annotation-driven/>

<bean id="transactionManager"
      class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

Again, I'm so sorry for re-asking such a common problem, but I must be missing some bit of knowledge that ties this all together.

Steve s.
  • 301
  • 1
  • 4
  • 13
  • I think it's better you start another question about this other problem, cause it's going to be confusing for those who are trying to find the same solution. – Diego Urenia Aug 27 '13 at 18:09
  • Yeah, I did thanks. I kinda hosed up this question. The nature of the situation has changed. I'll create a new one. Bottom line is [link](http://stackoverflow.com/questions/6451377/loading-context-in-spring-using-web-xml) fixes part. – Steve s. Aug 27 '13 at 18:23
  • ok, if my answer have helped you for your original problem, then you can check the answer as the right one. – Diego Urenia Aug 27 '13 at 18:28

1 Answers1

1

You haven't configured your Context in your web.xml, so when Spring tries to find its Context you get this error.

This shows how to configure Spring using a xml file, but you can also do this using a Java configuration based. You can find something here.

Community
  • 1
  • 1
Diego Urenia
  • 1,620
  • 2
  • 21
  • 28
  • Thx! - added context and systems deploys, but oddly the filter isn't working. (message during free marker: "could not initialize proxy - no Session") The only hint I have is a hibernate warning. Before adding "Context" the WARN message HHH000431 appeared once on deployment, now it is twice. Red herring? – Steve s. Aug 27 '13 at 17:25
  • can you edit your question with your filter code? Also check that out and see whether it helps or not: https://community.jboss.org/wiki/OpenSessioninView – Diego Urenia Aug 27 '13 at 17:29
  • Yes, I was missing ContextLoaderListener. – Steve s. Aug 27 '13 at 18:30