7

Como configurar o Spring Data + hibernate

Olá pessoal,

Sou novato aqui no stackoverflow e também em desenvolvimento java Web. Estou etudando algumas coisas do Spring Frameork e estou com uma dúvida de como posso configurar o Spring Data no meu Dynamic Project.

Abaixo segue os meus aquivos de configuração e arquitetura. Se puderem me ajudar agradeço muito.

Arquitetura

inserir a descrição da imagem aqui

persistence.xml

<persistence-unit name="cleanUpUP" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>

        <property name="dialect" value="org.hibernate.dialect.MySQLDialect" />

        <!-- Configuracoes do Hibernate -->
        <property name="hibernate.hbm2ddl.auto" value="update" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
        <property name="org.hibernate" value="info" />
        <property name="org.hibernate.SQL.level" value="debug" />
        <property name="org.hibernate.type.level" value="debug" />

    </properties>

</persistence-unit>

spring.xml

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                       http://www.springframework.org/schema/context http://www.springframework.org/schema/task/spring-context-3.0.xsd">

<!-- Basic Configurations -->
<context:annotation-config/>

<context:component-scan base-package="br.com.cleanUp.model"/>
<context:component-scan base-package="br.com.cleanUp.repository"/>
<context:component-scan base-package="br.com.cleanUp.service"/>
<context:component-scan base-package="br.com.cleanUp.controller"/>

<!-- SpringMVC -->
<import resource="spring-mvc.xml"/>

<!-- SpringData -->
<import resource="spring-jpa.xml"/>

spring-mvc

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<mvc:annotation-driven/>
<mvc:default-servlet-handler/>

<!-- i18n -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="WEB-INF/i18n"/>
    <property name="defaultEncoding" value="UTF-8"/>
    <property name="useCodeAsDefaultMessage" value="true"/>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.FixedLocaleResolver">
    <property name="defaultLocale" value="en"/>
</bean>

<!-- View Handler -->
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="favorPathExtension" value="true"/>
    <property name="mediaTypes">
        <map>
            <entry key="xml" value="text/xml"/>
            <entry key="json" value="application/json"/>
            <entry key="html" value="text/html"/>
            <entry key="less" value="text/html"/>
        </map>
    </property>
    <property name="viewResolvers">
        <list>
            <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
                <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
            </bean>
            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="prefix" value="/WEB-INF/views/"/>
                <property name="suffix" value=".jsp"/>
            </bean>
        </list>
    </property>
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
        </list>
    </property>
</bean>

spring-jpa objeto de dúvida

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:jpa="http://www.springframework.org/schema/data/jpa"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
                       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                       http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
                       http://www.springframework.org/schema/context http://www.springframework.org/schema/task/spring-context-3.0.xsd">

<!-- JPA Configurations -->

<!-- MINHA DÚVIDA É AQUI -->

<!-- Spring Data -->
<jpa:repositories base-package="br.com.cleanUp.repository"
                  entity-manager-factory-ref="entityManagerFactory"
                  transaction-manager-ref="transactionManager"/>

Se puderem me ajudar e me dar uma dica agradeceria muito

3
  • 2
    Você está com alguma dúvida especifica/erro?
    – Giovani
    Commented 25/08/2014 às 0:14
  • Recomendo que de uma olhada neste link por ser usuário novo: pt.stackoverflow.com/tour
    – Giovani
    Commented 25/08/2014 às 0:19
  • Achou alguma solução? Poste como resposta para ajudar outras pessoas.
    – Maniero
    Commented 16/10/2014 às 1:48

2 Respostas 2

3

Wellington,

Se o projeto estiver no início ainda, te aconselho muito a usar o Spring Boot com Spring Data JPA, ele abstrai muito as configurações do Spring e é muito fácil configurar o Spring Data JPA, da uma olhada nesse link: https://spring.io/guides/gs/accessing-data-jpa/

Se interessar e tiver dúvidas posso te ajudar.

Abraços

0

Relacionado ao JPA, são as "dependências" (em português):

SISTEMA DE GERENCIAMENTO DE DEPENDÊNCIA

 <dependencies> 
    <dependency> 
        <groupId> org.springframework.data </groupId> 
        <artifactId> spring-data-jpa </artifactId> 
        <version> 1.7.1.RELEASE </version> 
    </dependency> 
</dependencies>

Fonte: http://projects.spring.io/spring-data-jpa/

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .