Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring上下文配置_Java_Spring_Hibernate_Jsf_Spring Mvc - Fatal编程技术网

Java Spring上下文配置

Java Spring上下文配置,java,spring,hibernate,jsf,spring-mvc,Java,Spring,Hibernate,Jsf,Spring Mvc,我试图在我的web应用程序中用glassfish 4.0服务器配置spring+hibernate+jsf。我在持久层使用Hibernate,业务层使用spring,web层使用jsf。我已经正确地配置了hibernate和jsf层。但是,当我试图配置spring层时,它不起作用 为了配置数据库,我使用了MySQL Workbench,并且将hibernate层与数据库正确连接,所有POJO都正确创建 但是现在我试图添加spring层,它在我的应用程序上下文中给了我一个错误。显示的错误如下所示:

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

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

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

<?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>    
<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>
我的申请文件如下:

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

模范顾客
通知范本
塔塔曼托模型
模型历史公司
型号:Ventatrataminto
范本.议程
模型验证器
Trabajador模型
模型产品
org.hibernate.dialogue.derbydialogue
真的
真的

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

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

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


提前感谢

您的xml文件包含多个错误

  • 您的
    jee
    tx
    命名空间映射错误
  • 您的架构位置错误
  • 命名空间映射 这是为了创建特定名称空间的简写,而不是架构位置。因此,您必须使用名称空间uri

    xmlns:jee="http://www.springframework.org/schema/jee/spring-jee"
    xmlns:tx="http://www.springframework.org/schema/tx/spring-tx"
    
    它们还应该映射到类路径中的位置,或者显式映射到模式位置中。这些也是错误的

    模式位置 模式位置的语法是
    [namespace][schema location]
    ,就像
    bean
    名称空间中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时,还建议使用无版本模式,这将始终指向类路径中spring的最新版本

    试试这个:

    更改您的:

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

    在您的schemalocation中,使用以下命令更改部件:

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


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

    是否阅读了异常第13行无效我读过它,它似乎与jndi有关,但我已经用glassfish正确地创建了我的conecction池,并且我将其命名为“jdbc/centro_belleza_Batter”。我知道问题似乎就在这一行,但我不知道为什么,这可能是导入的库的问题???正如你所说,我已经尝试过了,但它不起作用,你在使用哪个spring库????我使用了Spring Framework 3.1.1.release名称空间和模式位置是由系统创建的,在创建应用程序上下文时我没有接触它们事实上它们是完全错误的…无论是您自己创建的还是您的系统创建的…现在我尝试使用:xsi:schemaLocation=“>我试图更改它,但它不起作用,可能是spring库有问题???我使用了spring Framework 3.1.1.RELEASE。并且架构位置是在创建应用程序上下文时由系统创建的
     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