1 Reply Latest reply on Sep 15, 2011 7:17 AM by Jakub Kohout

    Spring Roo app running on JBoss AS7

    Jakub Kohout Newbie

      Hey,

      I have generated a simple web application using spring roo and now i would like to deploy it into Jboss AS7. I've got myself into some troubles, that i don't know how to solve it.

      The application is using spring 3.0.5, spring security 3.0.5 and hibernate 3.6.4. First I have tried to launch that application on Tomcat 7 and even there it wasn't easy.

      I was still reporting an error :

      org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]

      Offending resource: file [D:\projekty\diplomka_workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\e-library\WEB-INF\classes\META-INF\spring\applicationContext-security.xml]

       

      I figgured out that for some reason tomcat didn't have spring security libraries, so I had to add them manualy into :

      workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\e-library\WEB-INF\lib\

       

      Than the application worked, but now i need to run it in JBoss.

      At the first attempt i didn't want to resolve persistence-unit of my META-INF/persistence.xml . So I looked at how to deploy spring app in JBoss and tried to change persistence.xml to look like this:

       

      <persistence xmlns="http://java.sun.com/xml/ns/persistence"

                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"

                xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

       

                <persistence-unit name="libraryPersistenceUnit"

                          transaction-type="JTA">

                          <provider>org.hibernate.ejb.HibernatePersistence</provider>

                          <jta-data-source>java:jboss/datasources/MySQL</jta-data-source>

                          <properties>

                                    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />

                                    <property name="hibernate.hbm2ddl.auto" value="none" />

                                    <property name="hibernate.connection.charSet" value="UTF-8" />

                                    <property name="jboss.entity.manager.factory.jndi.name"

                                              value="java:jboss/LibraryEntityManagerFactory" />

                          </properties>

                </persistence-unit>

      </persistence>

       

       

      and I deleted local datasource from META-INF/spring/applicationContext.xml definition and set it up through jndi on server side ..in standalone.xml.

       

      <datasource jndi-name="java:jboss/datasources/MySQL" pool-name="java:jboss/datasources/MySQL_Pool" enabled="true" jta="true" use-java-context="true" use-ccm="true">

                          <connection-url>

                              jdbc:mysql://localhost/e-library

                          </connection-url>

                          <driver>

                              mysql

                          </driver>

                          <security>

                              <user-name>

                                  library

                              </user-name>

                              <password>

                                  library

                              </password>

                          </security>

                      </datasource>

                      <drivers>

                          <driver name="mysql" module="com.mysql"/>

                          <driver name="h2" module="com.h2database.h2">

                              <xa-datasource-class>

                                  org.h2.jdbcx.JdbcDataSource

                              </xa-datasource-class>

                          </driver>

                      </drivers>

                  </datasources>

       

       

      and I also added module com.mysql with mysql driver into modules directory of JBoss AS7.

       

      and my META-INF/spring/applicationContext.xml looks like this:

       

      <beans xmlns="http://www.springframework.org/schema/beans"

                xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"

                xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"

                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

       

        <context:spring-configured />

        <context:component-scan base-package="cz.uhk.library">

                          <context:exclude-filter expression=".*_Roo_.*"

                                    type="regex" />

                          <context:exclude-filter expression="org.springframework.stereotype.Controller"

                                    type="annotation" />

                </context:component-scan>

       

        <tx:jta-transaction-manager />

       

      <jee:jndi-lookup id="entityManagerFactory" jndi-name="LibraryEntityManagerFactory"

                          expected-type="javax.persistence.EntityManagerFactory" />

       

      </beans>

       

      and there is also file META-INF/spring/applicationContext-security.xml which is in attached files.

       

      Than I runned the app again and got result:

      java.lang.ClassNotFoundException: org.springframework.security.core.userdetails.UserDetails from [Module "deployment.e-library-jboss.war:main" from Service Module Loader]

       

      I am bit puzzled here, because I thought that maven will provide all defined dependencies in pom.xml, but anyway I have defined moduled for spring security and added jboss-deployment-structure.xml.

       

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">

                <deployment>

                          <dependencies>

                                    <module name="org.springframework.security.core" slot="3.0.5"

                                              export="true" />

                                    <module name="org.springframework.security.config" slot="3.0.5"

                                              export="true" />

                                    <module name="org.springframework.security.web" slot="3.0.5"

                                              export="true" />

                                    <module name="org.springframework.security.taglibs" slot="3.0.5"

                                              export="true" />

                          </dependencies>

                </deployment>

      </jboss-deployment-structure>

       

       

      but, still the app is not running. The lates error is:

      ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/e-library-jboss]] (MSC service thread 1-3) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]

      Offending resource: "/D:/installed/jboss-as-7.0.1.Final/standalone/deployments/e-library-jboss.war/WEB-INF/classes/META-INF/spring/applicationContext-security.xml"

                at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68) [spring-beans-3.0.5.RELEASE.jar:]

       

       

      I don't know what I am doing  wrong...but it doesn't look like a coincidence that this last error is same as the one I got while deploying it on Tomcat.

      I am sorry if the reason is obvious, I am not any guru in that matter.

       

      Can anyone help please? If it is necessary I can provide the whole application for testing.

       

      Thanks in advance!