【问题标题】:Spring context configurationSpring上下文配置
【发布时间】:2014-04-10 13:38:28
【问题描述】:

我正在尝试使用 glassfish 4.0 服务器在我的 Web 应用程序中配置 spring + hibernate + jsf。我在持久层使用 Hibernate,在业务层使用 Spring,在 Web 层使用 jsf。我已经正确配置了 hibernate 和 jsf 层。但是当我尝试配置弹簧层时,它不起作用。

为了配置数据库,我使用了MySQL Workbench,并且我已经将hibernate层与数据库正确连接,所有POJOS都已正确创建。

但是现在我尝试添加弹簧层,它在我的应用程序上下文中给了我一个错误。显示的错误如下:

而我的应用文件是这样的:

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.

而且日志显示这个异常:

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).......

我的应用上下文显示如下:

<?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>    

问题似乎出在我的 jndi 声明中。创建 jdbc 的 glassfish-resources 如下所示:

<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>

谁能帮帮我???有人遇到同样的问题吗???

提前致谢!!!!

【问题讨论】:

  • 你读过异常吗? Line 13 in XML document from ServletContext resource [/WEB-INF/salon_bazter.xml] is invalid;
  • 我读过它,它似乎是 jndi 的问题,但我已经在 glassfish 中正确创建了我的连接池,我把它称为“jdbc/centro_belleza_bazter”。我知道问题似乎出在那一行,但我不知道为什么,可能是导入的库有问题???

标签: java spring hibernate jsf spring-mvc


【解决方案1】:

您的 xml 文件包含多个错误

  1. 您的 jeetx 命名空间映射错误
  2. 您的架构位置错误

命名空间映射

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"

这旨在为特定命名空间而不是架构位置创建简写。所以你必须使用命名空间 uri。

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

这些也应该映射到类路径中的位置,或者显式映射到您的架构位置。那些也是错误的

架构位置

 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">

架构位置的语法是 [namespace] [schema location],就像 beans 命名空间的 2 之上的语法一样。

 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

当使用带有命名空间的 spring 时,还建议使用 version less 模式,这将始终指向类路径中最新版本的 spring。

【讨论】:

【解决方案2】:

试试这个:

改变你的:

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

到:

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

并在您的架构位置中使用以下内容更改部分:

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/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd

注意:如果这是问题所在,那么您的 tx 命名空间可能存在类似问题。

【讨论】:

  • 我试过改了,还是不行,可能是spring库的问题???我使用了 Spring Framework 3.1.1.RELEASE。当我创建应用程序上下文时,系统已经创建了架构位置
猜你喜欢
  • 1970-01-01
  • 2011-05-07
  • 2016-11-15
  • 1970-01-01
  • 2017-03-07
  • 2022-01-12
  • 2014-12-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多