同じ Web アプリケーションで Spring-Data-JPA と Spring-Data-Rest を一緒に試していますが、正しく動作しません。アプリケーションには必要なすべての Maven 依存関係があり、それらは最新です。
2 つの Web 層を同時に使用することはできますか?
構成のどのようなエラーが考えられますか?
それらを正しく設定するための提案はありますか?
同じ Web アプリケーションで Spring-Data-JPA と Spring-Data-Rest を一緒に試していますが、正しく動作しません。アプリケーションには必要なすべての Maven 依存関係があり、それらは最新です。
2 つの Web 層を同時に使用することはできますか?
構成のどのようなエラーが考えられますか?
それらを正しく設定するための提案はありますか?
2 つのテクノロジを問題なく並べて使用しました。
Spring データ JPA を使用して作成されたリポジトリを持つ既存の Spring MVC アプリケーションがあります。次に、Spring データ REST を一番上に追加しました。
// Register and map the standard dispatcher servlet
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(mvcContext));
dispatcher.setInitParameter("contextConfigLocation", "/WEB-INF/spring/appServlet/servlet-context.xml");
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/app/*");
// Register the Spring data rest exporter servlet
ServletRegistration.Dynamic exporter = servletContext.addServlet("exporter", RepositoryRestExporterServlet.class);
exporter.addMapping("/rest/*");
<!--
NB. This pulls in Spring data JPA
and just about everything else you need.
-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>1.0.0.RC2</version>
</dependency>
xxx-export.xml
にファイルを追加する必要がありますMETA-INF/spring-data-rest
。これを既存のルート構成コンテキストに向けるだけです。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="../../root-context.xml"/>
</beans>
<context:component-scan base-package="my.package.spring"/>
<jpa:repositories base-package="my.package.spring.repo"/>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="entityManagerFactory" ...>
...
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="dataSource" ...>
...
</bean>
既存@Controller
の は引き続き で利用できlocalhost:8080/myapp/app/*
、新しい残りのエンドポイントは にエクスポートされlocalhost:8080/myapp/rest/*
ます。