DATACMNS-47 - Add support for JavaConfig based repository configuration.

Completely rewrote namespace bean definition parsing to be extendable more easily. Separated XML concerns from annotation based configuration. The central point to extend the namespace parsing for a certain module is now hidden behind the RepositoryConfigurationExtension interface (have a look at the RepositoryConfigurationExtensionSupport base class as well).
This commit is contained in:
Oliver Gierke
2012-07-05 17:16:03 +02:00
parent 464c3f048b
commit 96795f2980
36 changed files with 2176 additions and 1471 deletions

View File

@@ -433,7 +433,7 @@ List&lt;User&gt; findByLastname(String lastname, Pageable pageable);</programlis
definitions for the repository interfaces defined.</para>
<section id="repositories.create-instances.spring">
<title>Spring</title>
<title>XML Configuration</title>
<para>The easiest way to do so is by using the Spring namespace that
is shipped with each Spring Data module that supports the repository
@@ -501,19 +501,43 @@ List&lt;User&gt; findByLastname(String lastname, Pageable pageable);</programlis
instantiated.</para>
</example>
</simplesect>
</section>
<simplesect>
<title>Manual configuration</title>
<section id="repositories.create-instances.java-config">
<title>JavaConfig</title>
<para>If you'd rather like to manually define which repository
instances to create you can do this with nested <code>&lt;repository
/&gt;</code> elements.</para>
<para>The repository infrastructure can also be triggered using a
store-specific
<interfacename>@Enable${store}Repositories</interfacename> annotation
on a JavaConfig class. For an introduction into Java based
configuration of the Spring container please have a look at the
reference documentation.<footnote>
<para>JavaConfig in the Spring reference documentation - <ulink
url="http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-java"/></para>
</footnote></para>
<programlisting language="xml">&lt;repositories base-package="com.acme.repositories"&gt;
&lt;repository id="userRepository" /&gt;
&lt;/repositories&gt;
</programlisting>
</simplesect>
<para>A sample configuration to enable Spring Data repositories would
look something like this.</para>
<example>
<title>Sample annotation based repository configuration</title>
<programlisting>@Configuration
@EnableJpaRepositories("com.acme.repositories")
class ApplicationConfiguration {
@Bean
public EntityManagerFactory entityManagerFactory() {
// …
}
}</programlisting>
</example>
<para>Note that the sample uses the JPA specific annotation which
would have to be exchanged dependingon which store module you actually
use. The same applies to the definition of the
<interfacename>EntityManagerFactory</interfacename> bean. Please
consult the sections covering the store-specific configuration.</para>
</section>
<section id="repositories.create-instances.standalone">

View File

@@ -7,23 +7,21 @@
<section id="namespace-dao-config">
<title>The <code>&lt;repositories /&gt;</code> element</title>
<para>The <code>&lt;repositories /&gt;</code> element acts as container
for <code>&lt;repository /&gt;</code> elements or can be left empty to
trigger auto detection<footnote>
<para>The <code>&lt;repositories /&gt;</code> triggers the setup of the
Spring Data repository infrastructure. The most important attribute is
<code>base-package</code> which defines the package to scan for Spring
Data repository interfaces.<footnote>
<para>see <xref
linkend="repositories.create-instances.spring" /></para>
</footnote> of repository instances. Attributes defined for
<code>&lt;repositories /&gt;</code> are propagated to contained
<code>&lt;repository /&gt;</code> elements but can be overridden of
course.</para>
linkend="repositories.create-instances.spring"/></para>
</footnote></para>
<table>
<title>Attributes</title>
<tgroup cols="2">
<colspec colwidth="1*" />
<colspec colwidth="1*"/>
<colspec colwidth="2*" />
<colspec colwidth="2*"/>
<thead>
<row>
@@ -41,9 +39,7 @@
interfaces extending <interfacename>*Repository</interfacename>
(actual interface is determined by specific Spring Data module) in
auto detection mode. All packages below the configured package
will be scanned, too. In auto configuration mode (no nested
<code>&lt;repository /&gt;</code> elements) wildcards are also
allowed.</entry>
will be scanned, too. Wildcards are also allowed.</entry>
</row>
<row>
@@ -60,44 +56,8 @@
<entry>Determines the strategy to be used to create finder
queries. See <xref
linkend="repositories.query-methods.query-lookup-strategies" />
for details. Defaults to <code>create-if-not-found</code>.</entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section id="namespace-dao">
<title>The <code>&lt;repository /&gt;</code> element</title>
<para>The <code>&lt;repository /&gt;</code> element can contain all
attributes of <code>&lt;repositories /&gt;</code> except
<code>base-package</code>. This will result in overriding the values
configured in the surrounding <code>&lt;repositories /&gt;</code> element.
Thus here we will only document extended attributes.</para>
<table>
<title>Attributes</title>
<tgroup cols="2">
<colspec colwidth="1*" />
<colspec colwidth="2*" />
<tbody>
<row>
<entry><code>id</code></entry>
<entry>Defines the id of the bean the repository instance will be
registered under as well as the repository interface name.</entry>
</row>
<row>
<entry><code>custom-impl-ref</code></entry>
<entry>Defines a reference to a custom repository implementation
bean.</entry>
linkend="repositories.query-methods.query-lookup-strategies"/> for
details. Defaults to <code>create-if-not-found</code>.</entry>
</row>
</tbody>
</tgroup>