@@ -1156,13 +1156,13 @@ public interface UserRepository extends JpaRepository<User, Long> {
|
||||
<programlisting language="xml"><jpa:auditing auditor-aware-ref="yourAuditorAwareBean" /></programlisting>
|
||||
</example>
|
||||
|
||||
<para>As of Spring Data JPA 1.5, auditing can be enabled by annotating a
|
||||
configuration class with the <classname>@EnableJpaAuditing</classname>
|
||||
annotation.</para>
|
||||
|
||||
<example>
|
||||
<title>Activating auditing via Java configuration</title>
|
||||
|
||||
<para>As of Spring Data JPA 1.5, auditing can be enabled by annotating
|
||||
a configuration class with the
|
||||
<classname>EnableJpaAuditing</classname> annotation.</para>
|
||||
|
||||
<programlisting language="java">@Configuration
|
||||
@EnableJpaAuditing
|
||||
class Config {
|
||||
@@ -1172,17 +1172,17 @@ class Config {
|
||||
return new AuditorAwareImpl();
|
||||
}
|
||||
}</programlisting>
|
||||
|
||||
<para>If you expose a bean of type
|
||||
<interfacename>AuditorAware</interfacename> to the
|
||||
<interfacename>ApplicationContext</interfacename>, the auditing
|
||||
infrastructure will pick it up automatically and use it to determine
|
||||
the current user to be set on domain types. If you have multiple
|
||||
implementations registered in the
|
||||
<interfacename>ApplicationContext</interfacename>, you can select the
|
||||
one to be used by explicitly setting the auditorAwareRef attribute of
|
||||
<interfacename>@EnableJpaAuditing</interfacename>.</para>
|
||||
</example>
|
||||
|
||||
<para>If you expose a bean of type
|
||||
<interfacename>AuditorAware</interfacename> to the
|
||||
<interfacename>ApplicationContext</interfacename>, the auditing
|
||||
infrastructure will pick it up automatically and use it to determine the
|
||||
current user to be set on domain types. If you have multiple
|
||||
implementations registered in the
|
||||
<interfacename>ApplicationContext</interfacename>, you can select the
|
||||
one to be used by explicitly setting the <code>auditorAwareRef</code>
|
||||
attribute of <interfacename>@EnableJpaAuditing</interfacename>.</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.auditing.DateTimeProvider;
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
@@ -62,8 +61,8 @@ public @interface EnableJpaAuditing {
|
||||
boolean modifyOnCreate() default true;
|
||||
|
||||
/**
|
||||
* Configures a {@link DateTimeProvider} bean name that allows customizing the {@link DateTime} to be used for setting
|
||||
* creation and modification dates.
|
||||
* Configures a {@link DateTimeProvider} bean name that allows customizing the {@link org.joda.time.DateTime} to be
|
||||
* used for setting creation and modification dates.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@@ -59,8 +59,8 @@ class JpaAuditingRegistrar extends AuditingBeanDefinitionRegistrarSupport {
|
||||
@Override
|
||||
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
|
||||
|
||||
Assert.notNull(annotationMetadata, "annotationMetadata must not be null!");
|
||||
Assert.notNull(annotationMetadata, "registry must not be null!");
|
||||
Assert.notNull(annotationMetadata, "AnnotationMetadata must not be null!");
|
||||
Assert.notNull(registry, "BeanDefinitionRegistry must not be null!");
|
||||
|
||||
registerBeanConfigurerAspectIfNecessary(registry);
|
||||
super.registerBeanDefinitions(annotationMetadata, registry);
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JpaAuditingRegistrar}.
|
||||
*
|
||||
* @see DATAJPA-265
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class JpaAuditingRegistrarUnitTests {
|
||||
|
||||
JpaAuditingRegistrar registrar = new JpaAuditingRegistrar();
|
||||
|
||||
@Mock AnnotationMetadata metadata;
|
||||
@Mock BeanDefinitionRegistry registry;
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullAnnotationMetadata() {
|
||||
registrar.registerBeanDefinitions(null, registry);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullBeanDefinitionRegistry() {
|
||||
registrar.registerBeanDefinitions(metadata, null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user