简体   繁体   中英

Spring context configuration

I´m trying to configure spring + hibernate + jsf in my web application with a glassfish 4.0 server. I use Hibernate in the persistence layer, spring for the business layer and jsf for the web layer. I have configured the hibernate and jsf layers properly. But while I´m trying to configure the spring layer, it doesn´t work.

For configuring the database, I have use MySQL Workbench, and I have connected the hibernate layer with the database properly, all the POJOS are properly created.

But now Im trying to add the spring layer, and it gives me an error in my Application context. The error displayed shows as follows:

And my Aplication file is like this:

Error occurred during deployment: Exception while loading the app :java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 13 in XML document from ServletContext resource [/WEB-INF/salon_bazter.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 13; columnNumber: 90; cvc-complex-type.2.4.c: El comodín coincidente es estricto, pero no se ha encontrado ninguna declaración para el elemento 'jee:jndi-lookup'.. Please see server.log for more details.

And the log shows this exception:

ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException:org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 13 in XML document from ServletContext resource [/WEB-INF/salon_bazter.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 13; columnNumber: 90; cvc-complex-type.2.4.c: El comodín coincidente es estricto, pero no se ha encontrado ninguna declaración para el elemento 'jee:jndi-lookup'.
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5920)
at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2278)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1924)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:497)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:356).......

My Aplication context shows as follows:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:jee="http://www.springframework.org/schema/jee/spring-jee"
   xmlns:tx="http://www.springframework.org/schema/tx/spring-tx"

   xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
     http://www.springframework.org/schema/jee/spring-jee
     http://www.springframework.org/schema/jee/spring-jee.xsd
     http://www.springframework.org/schema/tx/spring-txd
     http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--Para obtener el pool de conexiones vía jndi name-->
<jee:jndi-lookup id="salonBazterDataSource" jndi-name="jdbc/centro_belleza_bazter" />

<!--Para declarar una factoría de Sesiones de hibernate-->
<bean id="miSessionFact"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="salonBazterDataSource" />
    <property name="annotatedClasses">
        <list>
            <value>model.Cliente</value>
            <value>model.Noticias</value>
            <value>model.Tratamiento</value>
            <value>model.Historico</value>
            <value>model.VentaTratamiento</value>
            <value>model.Agenda</value>
            <value>model.Proveedor</value>
            <value>model.Trabajador</value>
            <value>model.Producto</value>               

        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect" >org.hibernate.dialect.DerbyDialect</prop>
            <prop key="hibernate.show_sql" >true</prop>
            <prop key="hibernate.format_sql" >true</prop>
        </props>
    </property>
</bean>

<!--Para declarar un Gestor transaccional de Hibernate-->
<bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="miSessionFact" />
</bean>

<!--Para definir que el Contexto transaccional será administrado por contenedor-->
<tx:annotation-driven transaction-manager="transactionManager" />
<!--Para definir un bean de tipo noticiasService-->
 <bean id="noticiasService" class="negocio.clientes.NoticiasServiceImpl" >
    <property name="sessionFactory" ref="miSessionFact" />
</bean>    

The problem seems to be in my jndi declaration. The glassfish-resources where the jdbc is created, looks as follows:

<resources>

<jdbc-resource enabled="true" jndi-name="jdbc/centro_belleza_bazter" object-type="user" pool-name="connectionPoolBazter">
  <description/>
 </jdbc-resource>

<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="connectionPoolBazter" non-transactional-connections="false" ping="false" pool-resize-quantity="2" pooling="true" res-type="javax.sql.DataSource" statement-cache-size="0" statement-leak-reclaim="false" statement-leak-timeout-in-seconds="0" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="true">
<property name="URL" value="jdbc:mysql://localhost:3306/centro_belleza_bazter?zeroDateTimeBehavior=convertToNull"/>
<property name="User" value="root"/>
<property name="Password" value="root"/>
 </jdbc-connection-pool>
 </resources>

Could anybody help me??? Does anybody had the same problem???

Thanks in advance!!!!

Your xml file contains multiple errors

  1. Your jee and tx namespace mappings are wrong
  2. Your schema locations are wrong

namespace mappings

xmlns:jee="http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"
xmlns:tx="http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"

This is intended to create a shorthand to a particular namespace not a schema location. So you have to use the namespace uri.

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

These should map also to locations in either the class path or explicitly be mapped in your schema locations. Those are also wrong

Schema location

 http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/jee/spring-jee-2.5.xsd/spring-spring-jee-2.5.xsd-3.1.1.RELEASE.xsd
 http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/tx/spring-tx-2.5.xsd/spring-spring-tx-2.5.xsd-3.1.1.RELEASE.xsd">

The syntax for schema locations is [namespace] [schema location] , just as the one above the 2 for the beans namespace.

 http://www.springframework.org/schema/jee/spring-jee http://www.springframework.org/schema/jee/spring-jee.xsd
 http://www.springframework.org/schema/tx/spring-txd http://www.springframework.org/schema/tx/spring-tx.xsd

When using spring with namespace it is also advised to use the version less schema this will always point to the most recent version of spring in your class path.

Try this:

Change your:

xmlns:jee="http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"

to:

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

and in your schemalocation change the part with the:

http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd/spring-spring-jee-2.5.xsd-3.1.1.RELEASE.xsd

to:

http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd

Note: if this was the problem then you might have a similar one with the tx namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM