我正在尝试使用glassfish 4.0服务器在我的Web应用程序中配置spring + hibernate + jsf。我在持久层中使用Hibernate,在业务层使用spring,在Web层使用jsf。我已正确配置了hibernate和jsf层。但是当我尝试配置弹簧层时,它不起作用。
为了配置数据库,我使用了MySQL Workbench,并且已经将hibernate层与数据库正确连接,所有POJOS都已正确创建。
但是现在我试图添加spring层,它在我的Application上下文中给出了一个错误。显示的错误显示如下:
我的Aplication文件是这样的:
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>
有人能帮帮我吗?有没有人有同样的问题?
提前致谢!!!!
答案 0 :(得分:2)
您的xml文件包含多个错误
jee
和tx
命名空间映射错误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时,还建议使用版本较少的模式,这将始终指向类路径中最新版本的spring。
答案 1 :(得分:1)
试试这个:
改变你的:
xmlns:jee="http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"
为:
xmlns:jee="http://www.springframework.org/schema/jee"
并在您的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
为:
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
注意:如果这是问题,那么您可能与tx名称空间类似。