[2.1] Have problem loading Spring application-context after upgrading to Play 2.1

1,198 views
Skip to first unread message

Steven Kao

unread,
Feb 24, 2013, 11:20:10 AM2/24/13
to play-fr...@googlegroups.com
Hi,

Not completely sure if it is a problem raised from Play 2.1 or Scala 2.10, but after I upgrade my application from Play 2.0.4 to Play 2.1, my application raise the following exception at runtime when loading a page,

java.lang.ExceptionInInitializerError: null
at models.database.entities.Bookstore$.<init>(Bookstore.scala:118) ~[na:na]
at models.database.entities.Bookstore$.<clinit>(Bookstore.scala) ~[na:na]
at controllers.Admin$.<init>(Admin.scala:61) ~[na:na]
at controllers.Admin$.<clinit>(Admin.scala) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$5$$anonfun$apply$5.apply(routes_routing.scala:125) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$5$$anonfun$apply$5.apply(routes_routing.scala:125) ~[na:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [database/hibernate.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.util.ArrayList' to required type 'java.lang.Class[]' for property 'annotatedClasses'; nested exception is java.lang.IllegalArgumentException: Cannot find class [models.database.entities.Bookstore]

It seems like the Spring was unable to resolve the class I defined in "models.database.entities.Bookstore." when it is tries to initiate application-context. The hibernate bean definition looks like this 

   <bean id="hibernateClasses" class="org.springframework.beans.factory.config.ListFactoryBean">
        <property name="sourceList">
            <list>
                <value>models.database.entities.Bookstore</value>
                <value>models.database.entities.BookstoreFile</value>
                <value>models.database.entities.BookstoreLogoFile</value>
                <value>models.database.entities.SystemProperty</value>
            </list>
        </property>
    </bean>


I am completely puzzled about this error because when I run my scala-test unit tests, all the spring/hibernate work fine. But when I run my application, the error raise. Do anyone have clue what could be the problem? Thanks you guys help for so much! 

Steven Kao

unread,
Feb 24, 2013, 11:56:11 AM2/24/13
to play-fr...@googlegroups.com
It seems like Spring was unable to load the class that I defined in models directory. 


Here is the part of the exception stacktrace.  

Caused by: java.lang.IllegalArgumentException: Cannot find class [models.database.entities.Bookstore]
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:294) ~[spring-core.jar:3.1.2.RELEASE]
at org.springframework.beans.propertyeditors.ClassEditor.setAsText(ClassEditor.java:63) ~[spring-beans.jar:3.1.2.RELEASE]

And the documentation of resolveClassName() says

IllegalArgumentException - if the class name was not resolvable (that is, the class could not be found or the class file could not be loaded)

So I guess the question is: Does Play 2.1 change the way of loading classes defined in models directory? 


Thanks

Shishir Lamichhane

unread,
Apr 15, 2013, 8:31:55 AM4/15/13
to play-fr...@googlegroups.com
Hi, I have created a basic sample for the configuration of Play 2.1.1 Framework, Scala 2.10 Language, Spring3 for dependency injection and Hibernate4 as ORM.

Log4j.jar is used for logging.

Checkout the project : https://github.com/ceecer1/play211-scala210-spring3-Hibernate4.git

Edit the following to suit your db requirement in spring-context-data.xml.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="org.postgresql.Driver"/>
        <property name="url" value="jdbc:postgresql://localhost:5432/scalaspringhibernate"/>
        <property name="username" value="test"/>
        <property name="password" value="test"/>
    </bean>


cmd -> play run

Creates tables in the database.

Insert 1 or 2 rows manually in the User table after the db is created.

Change <prop key="hibernate.hbm2ddl.auto">
create</prop> to update

got to : http://localhost:9000/ and see the JSON result

This might be really helpful for you guys.

Enjoy SCALA.

Thanks,
ceecer.l...@gmail.com

Nilanjan Raychaudhuri

unread,
Apr 15, 2013, 5:18:59 PM4/15/13
to play-fr...@googlegroups.com


On Sunday, February 24, 2013 11:56:11 AM UTC-5, Steven Kao wrote:
It seems like Spring was unable to load the class that I defined in models directory. 


Here is the part of the exception stacktrace.  

Caused by: java.lang.IllegalArgumentException: Cannot find class [models.database.entities.Bookstore]
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:294) ~[spring-core.jar:3.1.2.RELEASE]
at org.springframework.beans.propertyeditors.ClassEditor.setAsText(ClassEditor.java:63) ~[spring-beans.jar:3.1.2.RELEASE]

And the documentation of resolveClassName() says

IllegalArgumentException - if the class name was not resolvable (that is, the class could not be found or the class file could not be loaded)

So I guess the question is: Does Play 2.1 change the way of loading classes defined in models directory?

Not that I can think of. I wonder whether this is happening because of different class loader. Is there a way you can pass the classloader play is using (play.api.Play.classLoader)

Nilanjan, Developer & Consultant
Typesafe Inc.
Twitter: @nraychaudhuri
Reply all
Reply to author
Forward
0 new messages