Spring - konfiguracja Hibernate'a

0

Mam problem z ustawieniami projektu springa.
Pisze project maven'owy. Plik konfiguracyjny applicationContext.xml, wygląda mniej więcej tak

 
<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:flow="http://www.springframework.org/schema/webflow-config"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
          http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
">
    <context:annotation-config/>
    
    <context:property-placeholder location="classpath*:crudentials.properties" />
    <context:component-scan base-package="com.cooperation.db.properties"/>
    
    <!--Hibertnate-->
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/mathcoop" resource-ref="true"/>
    <util:property name="hibernateProperties">        
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
        <prop key="hibernate.show_sql">false</prop>
    </util:property>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan" value="com.cooperation.db.model"/>
        <property name="hibernateProperties" ref="hibernateProperties"/>
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <tx:annotation-driven/>
</beans>

W logach tomcata otrzymuję:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 39 in XML document from ServletContext resource [/WEB-INF/conf/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: ...; columnNumber: ...; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'util:property'
Wydaje mi się, że problem jest z "hibernateProperties". Niby mam klasę "MySQL5InnoDBDialect" znajdującą się w jarce hibernate-3.2.6.ga.jar, ale spring tego nie widzi. Czy możliwe, że mam jakąś niezgodność wersji springa z wersją hibernata?

0

Ja w tej scheme nie widzę czegoś takiego jak "util:property".

0

Nie wiem czy dobrze rozumiem, ale w pliku konfiguracyjnym jest

<util:property name="hibernateProperties">

Natomiast wyżej:

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd

dodanie znacznika <code class="xml"> - @furious programming

0
<util:properties id="hibernateProperties">  
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">false</prop>
</util:properties>

Ewentualnie mozesz tak

<property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </props>
    </property>

zamiana znaczników <code class="java"> na <code class="xml"> - @furious programming

1

@michaelLew otwórz teraz tą scheme http://www.springframework.org/schema/util/spring-util-4.1.xsd i pokaż mi gdzie jest util:property bo ja widzę tylko util:properties

0

Ok. Udało mi się zmienić plik konfiguracyjny na taki, który działa:

<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:flow="http://www.springframework.org/schema/webflow-config"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
          http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd">
    <context:annotation-config/>
    
    <context:property-placeholder location="classpath*:crudentials.properties" />
    <context:component-scan base-package="com.cooperation.db.properties"/>
    
    <!--Hibertnate-->
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/mathcoop" resource-ref="true"/>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="hibernateProperties">   
            <props>     
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
                <prop key="hibernate.show_sql">false</prop>
            </props>
        </property>
        <property name="packagesToScan" value="com.cooperation.db.model"/>
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <tx:annotation-driven/>
</beans>

Dziękuję Wam za wskazówki. A skorzystałem z:
http://www.developer.com/java/integrating-hibernate-and-spring.html