diff --git a/spring-aop/src/main/java/org/aopalliance/intercept/Interceptor.java b/spring-aop/src/main/java/org/aopalliance/intercept/Interceptor.java
index 9f56db94048..f9742547291 100644
--- a/spring-aop/src/main/java/org/aopalliance/intercept/Interceptor.java
+++ b/spring-aop/src/main/java/org/aopalliance/intercept/Interceptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2018 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -33,7 +33,7 @@ import org.aopalliance.aop.Advice;
*
*
* class DebuggingInterceptor implements MethodInterceptor,
- * ConstructorInterceptor, FieldInterceptor {
+ * ConstructorInterceptor {
*
* Object invoke(MethodInvocation i) throws Throwable {
* debug(i.getMethod(), i.getThis(), i.getArgs());
@@ -45,16 +45,6 @@ import org.aopalliance.aop.Advice;
* return i.proceed();
* }
*
- * Object get(FieldAccess fa) throws Throwable {
- * debug(fa.getField(), fa.getThis(), null);
- * return fa.proceed();
- * }
- *
- * Object set(FieldAccess fa) throws Throwable {
- * debug(fa.getField(), fa.getThis(), fa.getValueToSet());
- * return fa.proceed();
- * }
- *
* void debug(AccessibleObject ao, Object this, Object value) {
* ...
* }
diff --git a/spring-aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests.java b/spring-aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests.java
index a0c220d079f..9c9552a2989 100644
--- a/spring-aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests.java
+++ b/spring-aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -20,7 +20,6 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.Resource;
import static org.junit.Assert.*;
import static org.springframework.tests.TestResourceUtils.*;
@@ -33,13 +32,11 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class TopLevelAopTagTests {
- private static final Resource CONTEXT = qualifiedResource(TopLevelAopTagTests.class, "context.xml");
-
@Test
- public void testParse() throws Exception {
+ public void testParse() {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
- XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
- reader.loadBeanDefinitions(CONTEXT);
+ new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
+ qualifiedResource(TopLevelAopTagTests.class, "context.xml"));
assertTrue(beanFactory.containsBeanDefinition("testPointcut"));
}
diff --git a/spring-aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java b/spring-aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java
index 455778c83e8..c5de9deee27 100644
--- a/spring-aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java
+++ b/spring-aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -36,6 +36,7 @@ public class PrototypeTargetTests {
private static final Resource CONTEXT = qualifiedResource(PrototypeTargetTests.class, "context.xml");
+
@Test
public void testPrototypeProxyWithPrototypeTarget() {
TestBeanImpl.constructionCount = 0;
@@ -64,12 +65,15 @@ public class PrototypeTargetTests {
assertEquals(10, interceptor.invocationCount);
}
- public static interface TestBean {
- public void doSomething();
+
+ public interface TestBean {
+
+ void doSomething();
}
public static class TestBeanImpl implements TestBean {
+
private static int constructionCount = 0;
public TestBeanImpl() {
@@ -83,6 +87,7 @@ public class PrototypeTargetTests {
public static class TestInterceptor implements MethodInterceptor {
+
private int invocationCount = 0;
@Override
diff --git a/spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java b/spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java
index 38f0bd9501f..4c2735abf23 100644
--- a/spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java
+++ b/spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -21,7 +21,6 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
@@ -36,13 +35,11 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class ExposeInvocationInterceptorTests {
- private static final Resource CONTEXT =
- qualifiedResource(ExposeInvocationInterceptorTests.class, "context.xml");
-
@Test
public void testXmlConfig() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
- new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
+ new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
+ qualifiedResource(ExposeInvocationInterceptorTests.class, "context.xml"));
ITestBean tb = (ITestBean) bf.getBean("proxy");
String name = "tony";
tb.setName(name);
@@ -74,6 +71,7 @@ abstract class ExposedInvocationTestBean extends TestBean {
class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean {
+
@Override
protected void assertions(MethodInvocation invocation) {
assertTrue(invocation.getThis() == this);
diff --git a/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyAutowireTests.java b/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyAutowireTests.java
index 4b5634f2b0a..67e1c30ddce 100644
--- a/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyAutowireTests.java
+++ b/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyAutowireTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -22,7 +22,6 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.Resource;
import static org.junit.Assert.*;
import static org.springframework.tests.TestResourceUtils.*;
@@ -34,16 +33,12 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class ScopedProxyAutowireTests {
- private static final Resource SCOPED_AUTOWIRE_FALSE_CONTEXT =
- qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireFalse.xml");
- private static final Resource SCOPED_AUTOWIRE_TRUE_CONTEXT =
- qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireTrue.xml");
-
-
@Test
public void testScopedProxyInheritsAutowireCandidateFalse() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
- new XmlBeanDefinitionReader(bf).loadBeanDefinitions(SCOPED_AUTOWIRE_FALSE_CONTEXT);
+ new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
+ qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireFalse.xml"));
+
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped"));
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped"));
assertFalse(bf.containsSingleton("scoped"));
@@ -55,7 +50,9 @@ public class ScopedProxyAutowireTests {
@Test
public void testScopedProxyReplacesAutowireCandidateTrue() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
- new XmlBeanDefinitionReader(bf).loadBeanDefinitions(SCOPED_AUTOWIRE_TRUE_CONTEXT);
+ new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
+ qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireTrue.xml"));
+
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped"));
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped"));
assertFalse(bf.containsSingleton("scoped"));
diff --git a/spring-aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java b/spring-aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java
index 68b9d26b9ce..b1a5b478d5c 100644
--- a/spring-aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java
+++ b/spring-aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -39,7 +39,8 @@ import static org.springframework.tests.TestResourceUtils.*;
public class RegexpMethodPointcutAdvisorIntegrationTests {
private static final Resource CONTEXT =
- qualifiedResource(RegexpMethodPointcutAdvisorIntegrationTests.class, "context.xml");
+ qualifiedResource(RegexpMethodPointcutAdvisorIntegrationTests.class, "context.xml");
+
@Test
public void testSinglePattern() throws Throwable {
diff --git a/spring-aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java b/spring-aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java
index 7eb90b8781f..051340bed9b 100644
--- a/spring-aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java
+++ b/spring-aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -25,7 +25,6 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.Resource;
import org.springframework.tests.aop.interceptor.SerializableNopInterceptor;
import org.springframework.tests.sample.beans.Person;
import org.springframework.tests.sample.beans.SerializablePerson;
@@ -41,31 +40,31 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class HotSwappableTargetSourceTests {
- private static final Resource CONTEXT = qualifiedResource(HotSwappableTargetSourceTests.class, "context.xml");
-
/** Initial count value set in bean factory XML */
private static final int INITIAL_COUNT = 10;
private DefaultListableBeanFactory beanFactory;
+
@Before
- public void setUp() throws Exception {
+ public void setup() {
this.beanFactory = new DefaultListableBeanFactory();
- new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT);
+ new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
+ qualifiedResource(HotSwappableTargetSourceTests.class, "context.xml"));
}
/**
* We must simulate container shutdown, which should clear threads.
*/
@After
- public void tearDown() {
+ public void close() {
// Will call pool.close()
this.beanFactory.destroySingletons();
}
+
/**
* Check it works like a normal invoker
- *
*/
@Test
public void testBasicFunctionality() {
@@ -106,18 +105,13 @@ public class HotSwappableTargetSourceTests {
assertEquals(target1.getCount(), proxied.getCount());
}
-
- /**
- *
- * @param invalid
- * @return the message
- */
- private IllegalArgumentException testRejectsSwapToInvalidValue(Object invalid) {
+ @Test
+ public void testRejectsSwapToNull() {
HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper");
IllegalArgumentException aopex = null;
try {
- swapper.swap(invalid);
- fail("Shouldn't be able to swap to invalid value [" + invalid + "]");
+ swapper.swap(null);
+ fail("Shouldn't be able to swap to invalid value");
}
catch (IllegalArgumentException ex) {
// Ok
@@ -126,19 +120,9 @@ public class HotSwappableTargetSourceTests {
// It shouldn't be corrupted, it should still work
testBasicFunctionality();
- return aopex;
+ assertTrue(aopex.getMessage().contains("null"));
}
- @Test
- public void testRejectsSwapToNull() {
- IllegalArgumentException ex = testRejectsSwapToInvalidValue(null);
- assertTrue(ex.getMessage().contains("null"));
- }
-
- // TODO test reject swap to wrong interface or class?
- // how to decide what's valid?
-
-
@Test
public void testSerialization() throws Exception {
SerializablePerson sp1 = new SerializablePerson();
@@ -165,4 +149,5 @@ public class HotSwappableTargetSourceTests {
assertEquals(sp1.getName(), p.getName());
}
+
}
diff --git a/spring-aop/src/test/java/org/springframework/aop/target/PrototypeTargetSourceTests.java b/spring-aop/src/test/java/org/springframework/aop/target/PrototypeTargetSourceTests.java
index 995ee9f89ac..528dce52aa0 100644
--- a/spring-aop/src/test/java/org/springframework/aop/target/PrototypeTargetSourceTests.java
+++ b/spring-aop/src/test/java/org/springframework/aop/target/PrototypeTargetSourceTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -19,11 +19,8 @@ package org.springframework.aop.target;
import org.junit.Before;
import org.junit.Test;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.SideEffectBean;
import static org.junit.Assert.*;
@@ -35,19 +32,20 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class PrototypeTargetSourceTests {
- private static final Resource CONTEXT = qualifiedResource(PrototypeTargetSourceTests.class, "context.xml");
-
/** Initial count value set in bean factory XML */
private static final int INITIAL_COUNT = 10;
- private BeanFactory beanFactory;
+ private DefaultListableBeanFactory beanFactory;
+
@Before
- public void setUp() throws Exception {
+ public void setup() {
this.beanFactory = new DefaultListableBeanFactory();
- new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory).loadBeanDefinitions(CONTEXT);
+ new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
+ qualifiedResource(PrototypeTargetSourceTests.class, "context.xml"));
}
+
/**
* Test that multiple invocations of the prototype bean will result
* in no change to visible state, as a new instance is used.
@@ -66,5 +64,4 @@ public class PrototypeTargetSourceTests {
assertEquals(INITIAL_COUNT, prototype.getCount());
}
-
}
diff --git a/spring-aop/src/test/java/org/springframework/aop/target/ThreadLocalTargetSourceTests.java b/spring-aop/src/test/java/org/springframework/aop/target/ThreadLocalTargetSourceTests.java
index 0ff97aa8a98..baa6005d0f8 100644
--- a/spring-aop/src/test/java/org/springframework/aop/target/ThreadLocalTargetSourceTests.java
+++ b/spring-aop/src/test/java/org/springframework/aop/target/ThreadLocalTargetSourceTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -21,7 +21,6 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.SideEffectBean;
@@ -34,26 +33,27 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class ThreadLocalTargetSourceTests {
- private static final Resource CONTEXT = qualifiedResource(ThreadLocalTargetSourceTests.class, "context.xml");
-
/** Initial count value set in bean factory XML */
private static final int INITIAL_COUNT = 10;
private DefaultListableBeanFactory beanFactory;
+
@Before
- public void setUp() throws Exception {
+ public void setup() {
this.beanFactory = new DefaultListableBeanFactory();
- new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT);
+ new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
+ qualifiedResource(ThreadLocalTargetSourceTests.class, "context.xml"));
}
/**
* We must simulate container shutdown, which should clear threads.
*/
- protected void tearDown() {
+ protected void close() {
this.beanFactory.destroySingletons();
}
+
/**
* Check we can use two different ThreadLocalTargetSources
* managing objects of different types without them interfering
@@ -141,7 +141,7 @@ public class ThreadLocalTargetSourceTests {
}
/**
- * Test for SPR-1442. Destroyed target should re-associated with thread and not throw NPE
+ * Test for SPR-1442. Destroyed target should re-associated with thread and not throw NPE.
*/
@Test
public void testReuseDestroyedTarget() {
diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java
index c21ab35c9f5..a18f0a32663 100644
--- a/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java
+++ b/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -50,10 +50,8 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class ConcurrentBeanFactoryTests {
- private static final Log logger = LogFactory.getLog(ConcurrentBeanFactoryTests.class);
- private static final Resource CONTEXT = qualifiedResource(ConcurrentBeanFactoryTests.class, "context.xml");
-
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd");
+
private static final Date DATE_1, DATE_2;
static {
@@ -66,27 +64,32 @@ public class ConcurrentBeanFactoryTests {
}
}
+
+ private static final Log logger = LogFactory.getLog(ConcurrentBeanFactoryTests.class);
+
private BeanFactory factory;
- private final Set set = Collections.synchronizedSet(new HashSet());
+ private final Set set = Collections.synchronizedSet(new HashSet<>());
+
+ private Throwable ex;
- private Throwable ex = null;
@Before
- public void setUp() throws Exception {
+ public void setup() throws Exception {
Assume.group(TestGroup.PERFORMANCE);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
- new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CONTEXT);
- factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
- @Override
- public void registerCustomEditors(PropertyEditorRegistry registry) {
- registry.registerCustomEditor(Date.class, new CustomDateEditor((DateFormat) DATE_FORMAT.clone(), false));
- }
- });
+ new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
+ qualifiedResource(ConcurrentBeanFactoryTests.class, "context.xml"));
+
+ factory.addPropertyEditorRegistrar(
+ registry -> registry.registerCustomEditor(Date.class,
+ new CustomDateEditor((DateFormat) DATE_FORMAT.clone(), false)));
+
this.factory = factory;
}
+
@Test
public void testSingleThread() {
for (int i = 0; i < 100; i++) {
diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java
index 83dd5af5c5f..027975beff4 100644
--- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java
+++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -21,10 +21,8 @@ import org.junit.Test;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.beans.factory.support.AutowireCandidateResolver;
-import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.Resource;
import static org.junit.Assert.*;
import static org.springframework.tests.TestResourceUtils.*;
@@ -38,13 +36,12 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class CustomAutowireConfigurerTests {
- private static final Resource CONTEXT = qualifiedResource(CustomAutowireConfigurerTests.class, "context.xml");
-
@Test
public void testCustomResolver() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
- BeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
- reader.loadBeanDefinitions(CONTEXT);
+ new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
+ qualifiedResource(CustomAutowireConfigurerTests.class, "context.xml"));
+
CustomAutowireConfigurer cac = new CustomAutowireConfigurer();
CustomResolver customResolver = new CustomResolver();
bf.setAutowireCandidateResolver(customResolver);
diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java
index 2f432e33be5..7c827c5b2ae 100644
--- a/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java
+++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -22,7 +22,6 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
@@ -37,9 +36,6 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class FieldRetrievingFactoryBeanTests {
- private static final Resource CONTEXT =
- qualifiedResource(FieldRetrievingFactoryBeanTests.class, "context.xml");
-
@Test
public void testStaticField() throws Exception {
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
@@ -127,7 +123,9 @@ public class FieldRetrievingFactoryBeanTests {
@Test
public void testBeanNameSyntaxWithBeanFactory() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
- new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
+ new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
+ qualifiedResource(FieldRetrievingFactoryBeanTests.class, "context.xml"));
+
TestBean testBean = (TestBean) bf.getBean("testBean");
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[0]);
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[1]);
diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java
index 5cc613d8ccd..d3535164a7b 100644
--- a/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java
+++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -27,7 +27,6 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.Resource;
import org.springframework.util.SerializationTestUtils;
import static org.junit.Assert.*;
@@ -42,25 +41,25 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class ObjectFactoryCreatingFactoryBeanTests {
- private static final Resource CONTEXT =
- qualifiedResource(ObjectFactoryCreatingFactoryBeanTests.class, "context.xml");
-
private DefaultListableBeanFactory beanFactory;
+
@Before
- public void setUp() {
+ public void setup() {
this.beanFactory = new DefaultListableBeanFactory();
- new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT);
+ new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
+ qualifiedResource(ObjectFactoryCreatingFactoryBeanTests.class, "context.xml"));
this.beanFactory.setSerializationId("test");
}
@After
- public void tearDown() {
+ public void close() {
this.beanFactory.setSerializationId(null);
}
+
@Test
- public void testFactoryOperation() throws Exception {
+ public void testFactoryOperation() {
FactoryTestBean testBean = beanFactory.getBean("factoryTestBean", FactoryTestBean.class);
ObjectFactory> objectFactory = testBean.getObjectFactory();
@@ -82,7 +81,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
}
@Test
- public void testProviderOperation() throws Exception {
+ public void testProviderOperation() {
ProviderTestBean testBean = beanFactory.getBean("providerTestBean", ProviderTestBean.class);
Provider> provider = testBean.getProvider();
@@ -152,7 +151,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
}
@Test
- public void testEnsureOFBFBReportsThatItActuallyCreatesObjectFactoryInstances() throws Exception {
+ public void testEnsureOFBFBReportsThatItActuallyCreatesObjectFactoryInstances() {
assertEquals("Must be reporting that it creates ObjectFactory instances (as per class contract).",
ObjectFactory.class, new ObjectFactoryCreatingFactoryBean().getObjectType());
}
diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java
index 2a81acb06fa..dcca770141c 100644
--- a/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java
+++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -25,7 +25,6 @@ import org.junit.Test;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
@@ -40,12 +39,11 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class SimpleScopeTests {
- private static final Resource CONTEXT = qualifiedResource(SimpleScopeTests.class, "context.xml");
-
private DefaultListableBeanFactory beanFactory;
+
@Before
- public void setUp() {
+ public void setup() {
beanFactory = new DefaultListableBeanFactory();
Scope scope = new NoOpScope() {
private int index;
@@ -69,10 +67,11 @@ public class SimpleScopeTests {
assertEquals("myScope", scopeNames[0]);
assertSame(scope, beanFactory.getRegisteredScope("myScope"));
- XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(beanFactory);
- xbdr.loadBeanDefinitions(CONTEXT);
+ new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
+ qualifiedResource(SimpleScopeTests.class, "context.xml"));
}
+
@Test
public void testCanGetScopedObject() {
TestBean tb1 = (TestBean) beanFactory.getBean("usesScope");
diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java
index adfe6176cb1..7345475d9bd 100644
--- a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java
+++ b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2018 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -24,7 +24,6 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
@@ -37,8 +36,6 @@ import static org.springframework.tests.TestResourceUtils.*;
*/
public class CustomProblemReporterTests {
- private static final Resource CONTEXT = qualifiedResource(CustomProblemReporterTests.class, "context.xml");
-
private CollatingProblemReporter problemReporter;
private DefaultListableBeanFactory beanFactory;
@@ -47,16 +44,17 @@ public class CustomProblemReporterTests {
@Before
- public void setUp() {
+ public void setup() {
this.problemReporter = new CollatingProblemReporter();
this.beanFactory = new DefaultListableBeanFactory();
this.reader = new XmlBeanDefinitionReader(this.beanFactory);
this.reader.setProblemReporter(this.problemReporter);
}
+
@Test
public void testErrorsAreCollated() {
- this.reader.loadBeanDefinitions(CONTEXT);
+ this.reader.loadBeanDefinitions(qualifiedResource(CustomProblemReporterTests.class, "context.xml"));
assertEquals("Incorrect number of errors collated", 4, this.problemReporter.getErrors().length);
TestBean bean = (TestBean) this.beanFactory.getBean("validBean");
diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java b/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java
index 3afadd4fb68..a07c439630a 100644
--- a/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java
+++ b/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java
@@ -86,7 +86,8 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
public Flux decode(Publisher input, ResolvableType elementType,
@Nullable MimeType mimeType, @Nullable Map hints) {
- Flux tokens = Jackson2Tokenizer.tokenize(Flux.from(input), this.jsonFactory, true);
+ Flux tokens = Jackson2Tokenizer.tokenize(
+ Flux.from(input), this.jsonFactory, getObjectMapper().getDeserializationContext(), true);
return decodeInternal(tokens, elementType, mimeType, hints);
}
@@ -94,7 +95,8 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
public Mono decodeToMono(Publisher input, ResolvableType elementType,
@Nullable MimeType mimeType, @Nullable Map hints) {
- Flux tokens = Jackson2Tokenizer.tokenize(Flux.from(input), this.jsonFactory, false);
+ Flux tokens = Jackson2Tokenizer.tokenize(
+ Flux.from(input), this.jsonFactory, getObjectMapper().getDeserializationContext(), false);
return decodeInternal(tokens, elementType, mimeType, hints).singleOrEmpty();
}
diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java
index ff3efa860cc..bfb5e450045 100644
--- a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java
+++ b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2017 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -119,7 +119,7 @@ public abstract class Jackson2CodecSupport {
@Nullable
protected MethodParameter getParameter(ResolvableType type) {
- return type.getSource() instanceof MethodParameter ? (MethodParameter) type.getSource() : null;
+ return (type.getSource() instanceof MethodParameter ? (MethodParameter) type.getSource() : null);
}
@Nullable
diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java
index 8af3dffa18a..de9cfaaef22 100644
--- a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java
+++ b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2018 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -26,13 +26,13 @@ import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.async.ByteArrayFeeder;
+import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.util.TokenBuffer;
import reactor.core.publisher.Flux;
import org.springframework.core.codec.DecodingException;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
-import org.springframework.util.Assert;
/**
* {@link Function} to transform a JSON stream of arbitrary size, byte array
@@ -40,12 +40,16 @@ import org.springframework.util.Assert;
* well-formed JSON object.
*
* @author Arjen Poutsma
+ * @author Rossen Stoyanchev
+ * @author Juergen Hoeller
* @since 5.0
*/
final class Jackson2Tokenizer {
private final JsonParser parser;
+ private final DeserializationContext deserializationContext;
+
private final boolean tokenizeArrayElements;
private TokenBuffer tokenBuffer;
@@ -59,36 +63,16 @@ final class Jackson2Tokenizer {
private final ByteArrayFeeder inputFeeder;
- private Jackson2Tokenizer(JsonParser parser, boolean tokenizeArrayElements) {
- Assert.notNull(parser, "'parser' must not be null");
+ private Jackson2Tokenizer(
+ JsonParser parser, DeserializationContext deserializationContext, boolean tokenizeArrayElements) {
this.parser = parser;
+ this.deserializationContext = deserializationContext;
this.tokenizeArrayElements = tokenizeArrayElements;
- this.tokenBuffer = new TokenBuffer(parser);
+ this.tokenBuffer = new TokenBuffer(parser, deserializationContext);
this.inputFeeder = (ByteArrayFeeder) this.parser.getNonBlockingInputFeeder();
}
- /**
- * Tokenize the given {@code Flux} into {@code Flux}.
- * @param dataBuffers the source data buffers
- * @param jsonFactory the factory to use
- * @param tokenizeArrayElements if {@code true} and the "top level" JSON
- * object is an array, each element is returned individually, immediately
- * after it is received.
- * @return the result token buffers
- */
- public static Flux tokenize(Flux dataBuffers, JsonFactory jsonFactory,
- boolean tokenizeArrayElements) {
-
- try {
- JsonParser parser = jsonFactory.createNonBlockingByteArrayParser();
- Jackson2Tokenizer tokenizer = new Jackson2Tokenizer(parser, tokenizeArrayElements);
- return dataBuffers.flatMap(tokenizer::tokenize, Flux::error, tokenizer::endOfInput);
- }
- catch (IOException ex) {
- return Flux.error(ex);
- }
- }
private Flux tokenize(DataBuffer dataBuffer) {
byte[] bytes = new byte[dataBuffer.readableByteCount()];
@@ -100,8 +84,7 @@ final class Jackson2Tokenizer {
return parseTokenBufferFlux();
}
catch (JsonProcessingException ex) {
- return Flux.error(new DecodingException(
- "JSON decoding error: " + ex.getOriginalMessage(), ex));
+ return Flux.error(new DecodingException("JSON decoding error: " + ex.getOriginalMessage(), ex));
}
catch (IOException ex) {
return Flux.error(ex);
@@ -114,8 +97,7 @@ final class Jackson2Tokenizer {
return parseTokenBufferFlux();
}
catch (JsonProcessingException ex) {
- return Flux.error(new DecodingException(
- "JSON decoding error: " + ex.getOriginalMessage(), ex));
+ return Flux.error(new DecodingException("JSON decoding error: " + ex.getOriginalMessage(), ex));
}
catch (IOException ex) {
return Flux.error(ex);
@@ -128,12 +110,11 @@ final class Jackson2Tokenizer {
while (true) {
JsonToken token = this.parser.nextToken();
// SPR-16151: Smile data format uses null to separate documents
- if ((token == JsonToken.NOT_AVAILABLE) ||
+ if (token == JsonToken.NOT_AVAILABLE ||
(token == null && (token = this.parser.nextToken()) == null)) {
break;
}
updateDepth(token);
-
if (!this.tokenizeArrayElements) {
processTokenNormal(token, result);
}
@@ -164,10 +145,9 @@ final class Jackson2Tokenizer {
private void processTokenNormal(JsonToken token, List result) throws IOException {
this.tokenBuffer.copyCurrentEvent(this.parser);
- if ((token.isStructEnd() || token.isScalarValue()) &&
- this.objectDepth == 0 && this.arrayDepth == 0) {
+ if ((token.isStructEnd() || token.isScalarValue()) && this.objectDepth == 0 && this.arrayDepth == 0) {
result.add(this.tokenBuffer);
- this.tokenBuffer = new TokenBuffer(this.parser);
+ this.tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
}
}
@@ -177,11 +157,10 @@ final class Jackson2Tokenizer {
this.tokenBuffer.copyCurrentEvent(this.parser);
}
- if (this.objectDepth == 0 &&
- (this.arrayDepth == 0 || this.arrayDepth == 1) &&
+ if (this.objectDepth == 0 && (this.arrayDepth == 0 || this.arrayDepth == 1) &&
(token == JsonToken.END_OBJECT || token.isScalarValue())) {
result.add(this.tokenBuffer);
- this.tokenBuffer = new TokenBuffer(this.parser);
+ this.tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
}
}
@@ -190,4 +169,26 @@ final class Jackson2Tokenizer {
(token == JsonToken.END_ARRAY && this.arrayDepth == 0));
}
+
+ /**
+ * Tokenize the given {@code Flux} into {@code Flux}.
+ * @param dataBuffers the source data buffers
+ * @param jsonFactory the factory to use
+ * @param tokenizeArrayElements if {@code true} and the "top level" JSON object is
+ * an array, each element is returned individually immediately after it is received
+ * @return the resulting token buffers
+ */
+ public static Flux tokenize(Flux dataBuffers, JsonFactory jsonFactory,
+ DeserializationContext deserializationContext, boolean tokenizeArrayElements) {
+
+ try {
+ JsonParser parser = jsonFactory.createNonBlockingByteArrayParser();
+ Jackson2Tokenizer tokenizer = new Jackson2Tokenizer(parser, deserializationContext, tokenizeArrayElements);
+ return dataBuffers.flatMap(tokenizer::tokenize, Flux::error, tokenizer::endOfInput);
+ }
+ catch (IOException ex) {
+ return Flux.error(ex);
+ }
+ }
+
}
diff --git a/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java
index 69a22bbb1af..1e8fba2055d 100644
--- a/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java
+++ b/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2018 the original author or authors.
+ * Copyright 2002-2019 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.
@@ -39,11 +39,10 @@ import org.springframework.web.context.ServletContextAware;
/**
* Subclass of {@link GenericApplicationContext}, suitable for web environments.
*
- * Implements the
- * {@link org.springframework.web.context.ConfigurableWebApplicationContext},
- * but is not intended for declarative setup in {@code web.xml}. Instead,
- * it is designed for programmatic setup, for example for building nested contexts or
- * for use within Spring 3.1 {@link org.springframework.web.WebApplicationInitializer org.springframework.web.WebApplicationInitializers}.
+ *
Implements {@link org.springframework.web.context.ConfigurableWebApplicationContext},
+ * but is not intended for declarative setup in {@code web.xml}. Instead, it is designed
+ * for programmatic setup, for example for building nested contexts or for use within
+ * {@link org.springframework.web.WebApplicationInitializer WebApplicationInitializers}.
*
*
If you intend to implement a WebApplicationContext that reads bean definitions
* from configuration files, consider deriving from AbstractRefreshableWebApplicationContext,
diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java
index 0556f2ffc89..a3ac0dea091 100644
--- a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java
+++ b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java
@@ -42,18 +42,13 @@ import org.springframework.http.MediaType;
import org.springframework.http.codec.Pojo;
import org.springframework.util.MimeType;
-import static java.util.Arrays.asList;
-import static java.util.Collections.emptyMap;
-import static java.util.Collections.singletonMap;
+import static java.util.Arrays.*;
+import static java.util.Collections.*;
import static org.junit.Assert.*;
-import static org.springframework.core.ResolvableType.forClass;
-import static org.springframework.http.MediaType.APPLICATION_JSON;
-import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8;
-import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON;
-import static org.springframework.http.MediaType.APPLICATION_XML;
-import static org.springframework.http.codec.json.Jackson2JsonDecoder.JSON_VIEW_HINT;
-import static org.springframework.http.codec.json.JacksonViewBean.MyJacksonView1;
-import static org.springframework.http.codec.json.JacksonViewBean.MyJacksonView3;
+import static org.springframework.core.ResolvableType.*;
+import static org.springframework.http.MediaType.*;
+import static org.springframework.http.codec.json.Jackson2JsonDecoder.*;
+import static org.springframework.http.codec.json.JacksonViewBean.*;
/**
* Unit tests for {@link Jackson2JsonDecoder}.
@@ -67,10 +62,12 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase {
private static final long serialVersionUID = 1L;
@@ -254,8 +253,7 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase source = Flux.just(buffer)
.concatWith(Flux.error(new RuntimeException()));
- Flux result = Jackson2Tokenizer.tokenize(source, this.jsonFactory, true);
+ Flux result = Jackson2Tokenizer.tokenize(
+ source, this.jsonFactory, this.objectMapper.getDeserializationContext(), true);
StepVerifier.create(result)
.expectError(RuntimeException.class)
@@ -195,7 +198,8 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
@Test // SPR-16521
public void jsonEOFExceptionIsWrappedAsDecodingError() {
Flux source = Flux.just(stringBuffer("{\"status\": \"noClosingQuote}"));
- Flux tokens = Jackson2Tokenizer.tokenize(source, this.jsonFactory, false);
+ Flux tokens = Jackson2Tokenizer.tokenize(
+ source, this.jsonFactory, this.objectMapper.getDeserializationContext(), false);
StepVerifier.create(tokens)
.expectError(DecodingException.class)
@@ -204,10 +208,9 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
private void testTokenize(List source, List expected, boolean tokenizeArrayElements) {
-
Flux tokenBufferFlux = Jackson2Tokenizer.tokenize(
Flux.fromIterable(source).map(this::stringBuffer),
- this.jsonFactory,
+ this.jsonFactory, this.objectMapper.getDeserializationContext(),
tokenizeArrayElements);
Flux result = tokenBufferFlux
@@ -234,7 +237,6 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
}
-
private static class JSONAssertConsumer implements Consumer {
private final String expected;
@@ -253,4 +255,5 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
}
}
}
+
}
diff --git a/src/docs/asciidoc/core.adoc b/src/docs/asciidoc/core.adoc
index cca7b745411..f2849ecbbfb 100644
--- a/src/docs/asciidoc/core.adoc
+++ b/src/docs/asciidoc/core.adoc
@@ -10,16 +10,16 @@
This part of the reference documentation covers all the technologies that are
absolutely integral to the Spring Framework.
-Foremost amongst these is the Spring Framework's Inversion of Control (IoC) container. A
-thorough treatment of the Spring Framework's IoC container is closely followed by
-comprehensive coverage of Spring's Aspect-Oriented Programming (AOP) technologies. The
-Spring Framework has its own AOP framework, which is conceptually easy to understand
-and which successfully addresses the 80% sweet spot of AOP requirements in Java
-enterprise programming.
+Foremost amongst these is the Spring Framework's Inversion of Control (IoC) container.
+A thorough treatment of the Spring Framework's IoC container is closely followed by
+comprehensive coverage of Spring's Aspect-Oriented Programming (AOP) technologies.
+The Spring Framework has its own AOP framework, which is conceptually easy to
+understand and which successfully addresses the 80% sweet spot of AOP requirements
+in Java enterprise programming.
Coverage of Spring's integration with AspectJ (currently the richest -- in terms of
-features -- and certainly most mature AOP implementation in the Java enterprise space) is
-also provided.
+features -- and certainly most mature AOP implementation in the Java enterprise space)
+is also provided.
include::core/core-beans.adoc[leveloffset=+1]
diff --git a/src/docs/asciidoc/core/core-aop-api.adoc b/src/docs/asciidoc/core/core-aop-api.adoc
index fe52c912372..ec6a5a5ef2c 100644
--- a/src/docs/asciidoc/core/core-aop-api.adoc
+++ b/src/docs/asciidoc/core/core-aop-api.adoc
@@ -1,14 +1,10 @@
[[aop-api]]
= Spring AOP APIs
-The previous chapter described the Spring's support for AOP with
-@AspectJ and schema-based aspect definitions. In this chapter, we discuss the lower-level
-Spring AOP APIs and the AOP support typically used in Spring 1.2 applications. For new
-applications, we recommend the use of the Spring 2.0 and later AOP support described in
-the previous chapter. However, when you work with existing applications (or when you read books
-and articles), you may come across Spring 1.2-style examples. Spring 5 remains backwards
-compatible with Spring 1.2, and everything described in this chapter is fully supported
-in Spring 5.
+The previous chapter described the Spring's support for AOP with @AspectJ and schema-based
+aspect definitions. In this chapter, we discuss the lower-level Spring AOP APIs. For common
+applications, we recommend the use of Spring AOP with AspectJ pointcuts as described in the
+previous chapter.
@@ -111,7 +107,7 @@ Since 2.0, the most important type of pointcut used by Spring is
`org.springframework.aop.aspectj.AspectJExpressionPointcut`. This is a pointcut that
uses an AspectJ-supplied library to parse an AspectJ pointcut expression string.
-See the <> for a discussion of supported AspectJ pointcut primitives.
+See the <> for a discussion of supported AspectJ pointcut primitives.
@@ -241,8 +237,7 @@ following example shows how to subclass `StaticMethodMatcherPointcut`:
----
There are also superclasses for dynamic pointcuts.
-
-You can use custom pointcuts with any advice type in Spring 1.0 RC2 and above.
+You can use custom pointcuts with any advice type.
@@ -996,8 +991,7 @@ to consider:
and included in the spring-core JAR. In other words, CGLIB-based AOP works "`out of
the box`", as do JDK dynamic proxies.
-There is little performance difference between CGLIB proxying and dynamic proxies. As of
-Spring 1.0, dynamic proxies are slightly faster. However, this may change in the future.
+There is little performance difference between CGLIB proxying and dynamic proxies.
Performance should not be a decisive consideration in this case.
@@ -1092,7 +1086,7 @@ we override the transaction propagation settings:
Note that in the parent bean example, we explicitly marked the parent bean definition as
being abstract by setting the `abstract` attribute to `true`, as described
-<>, so that it may not actually ever be
+<>, so that it may not actually ever be
instantiated. Application contexts (but not simple bean factories), by default,
pre-instantiate all singletons. Therefore, it is important (at least for singleton beans)
that, if you have a (parent) bean definition that you intend to use only as a template,
@@ -1226,9 +1220,7 @@ Depending on how you created the proxy, you can usually set a `frozen` flag. In
case, the `Advised` `isFrozen()` method returns `true`, and any attempts to modify
advice through addition or removal results in an `AopConfigException`. The ability
to freeze the state of an advised object is useful in some cases (for example, to
-prevent calling code removing a security interceptor). It may also be used in Spring 1.1
-to allow aggressive optimization if runtime advice modification is known not to be
-required.
+prevent calling code removing a security interceptor).
diff --git a/src/docs/asciidoc/core/core-aop.adoc b/src/docs/asciidoc/core/core-aop.adoc
index 6e725c080b1..ab63e349d1a 100644
--- a/src/docs/asciidoc/core/core-aop.adoc
+++ b/src/docs/asciidoc/core/core-aop.adoc
@@ -2,33 +2,31 @@
= Aspect Oriented Programming with Spring
Aspect-oriented Programming (AOP) complements Object-oriented Programming (OOP) by
-providing another way of thinking about program structure. The key unit of modularity in
-OOP is the class, whereas in AOP the unit of modularity is the aspect. Aspects
+providing another way of thinking about program structure. The key unit of modularity
+in OOP is the class, whereas in AOP the unit of modularity is the aspect. Aspects
enable the modularization of concerns (such as transaction management) that cut across
-multiple types and objects. (Such concerns are often termed "`crosscutting`" concerns in
-AOP literature.)
+multiple types and objects. (Such concerns are often termed "`crosscutting`" concerns
+in AOP literature.)
One of the key components of Spring is the AOP framework. While the Spring IoC
container does not depend on AOP (meaning you do not need to use AOP if you don't want
to), AOP complements Spring IoC to provide a very capable middleware solution.
-.Spring 2.0+ AOP
+.Spring AOP with AspectJ pointcuts
****
-Spring 2.0 introduced a simpler and more powerful way of writing custom aspects by using
-either a <> or the <>. Both of these styles offer fully typed advice and use of the AspectJ pointcut
-language while still using Spring AOP for weaving.
-
-This chapter discusses the Spring 2.0+ schema- and @AspectJ-based AOP support.
-The lower-level AOP support, as commonly exposed in Spring 1.2 applications, is
-discussed in <>.
+Spring provides simple and powerful ways of writing custom aspects by using either a
+<> or the <>.
+Both of these styles offer fully typed advice and use of the AspectJ pointcut language
+while still using Spring AOP for weaving.
+
+This chapter discusses the schema- and @AspectJ-based AOP support.
+The lower-level AOP support is discussed in <>.
****
AOP is used in the Spring Framework to:
-* Provide declarative enterprise services, especially as a replacement for EJB
- declarative services. The most important such service is
- <>.
+* Provide declarative enterprise services. The most important such service is
+ <>.
* Let users implement custom aspects, complementing their use of OOP with AOP.
NOTE: If you are interested only in generic declarative services or other pre-packaged
@@ -48,7 +46,7 @@ However, it would be even more confusing if Spring used its own terminology.
* Aspect: A modularization of a concern that cuts across multiple classes.
Transaction management is a good example of a crosscutting concern in enterprise Java
applications. In Spring AOP, aspects are implemented by using regular classes
- (the <>) or regular classes annotated with the
+ (the <>) or regular classes annotated with the
`@Aspect` annotation (the <>).
* Join point: A point during the execution of a program, such as the execution of a
method or the handling of an exception. In Spring AOP, a join point always
@@ -104,14 +102,14 @@ the same thing. Using the most specific advice type provides a simpler programmi
with less potential for errors. For example, you do not need to invoke the `proceed()`
method on the `JoinPoint` used for around advice, and, hence, you cannot fail to invoke it.
-In Spring 2.0, all advice parameters are statically typed so that you work with advice
-parameters of the appropriate type (the type of the return value from a method execution
-for example) rather than `Object` arrays.
+All advice parameters are statically typed so that you work with advice parameters of
+the appropriate type (e.g. the type of the return value from a method execution) rather
+than `Object` arrays.
The concept of join points matched by pointcuts is the key to AOP, which distinguishes
it from older technologies offering only interception. Pointcuts enable advice to be
-targeted independently of the object-oriented hierarchy. For example, you can apply an around advice
-providing declarative transaction management to a set of methods that span
+targeted independently of the object-oriented hierarchy. For example, you can apply an
+around advice providing declarative transaction management to a set of methods that span
multiple objects (such as all business operations in the service layer).
@@ -149,8 +147,8 @@ frameworks such as AspectJ are valuable and that they are complementary, rather
competition. Spring seamlessly integrates Spring AOP and IoC with AspectJ, to enable
all uses of AOP within a consistent Spring-based application
architecture. This integration does not affect the Spring AOP API or the AOP Alliance
-API. Spring AOP remains backward-compatible. See <> for a
-discussion of the Spring AOP APIs.
+API. Spring AOP remains backward-compatible. See <>
+for a discussion of the Spring AOP APIs.
[NOTE]
====
@@ -171,8 +169,8 @@ configuration-style approach. The fact that this chapter chooses to introduce th
@AspectJ-style approach first should not be taken as an indication that the Spring team
favors the @AspectJ annotation-style approach over the Spring XML configuration-style.
-See <> for a more complete discussion of the "`whys and wherefores`" of each
-style.
+See <> for a more complete discussion of the "`whys and wherefores`" of
+each style.
====
@@ -188,7 +186,7 @@ Spring AOP can also use CGLIB proxies. This is necessary to proxy classes rather
interfaces. By default, CGLIB is used if a business object does not implement an
interface. As it is good practice to program to interfaces rather than classes, business
classes normally implement one or more business interfaces. It is possible to
-<>, in those (hopefully rare) cases where you
+<>, in those (hopefully rare) cases where you
need to advise a method that is not declared on an interface or where you need to
pass a proxied object to a method as a concrete type.
@@ -209,8 +207,8 @@ interprets the same annotations as AspectJ 5, using a library supplied by Aspect
for pointcut parsing and matching. The AOP runtime is still pure Spring AOP, though, and
there is no dependency on the AspectJ compiler or weaver.
-NOTE: Using the AspectJ compiler and weaver enables use of the full AspectJ language and is
-discussed in <>.
+NOTE: Using the AspectJ compiler and weaver enables use of the full AspectJ language and
+is discussed in <>.
@@ -259,9 +257,9 @@ element, as the following example shows:
----
This assumes that you use schema support as described in
-<>. See
-<> for how to import the tags in the `aop`
-namespace.
+<>.
+See <> for how to
+import the tags in the `aop` namespace.
@@ -273,8 +271,8 @@ class that is an @AspectJ aspect (has the `@Aspect` annotation) is automatically
detected by Spring and used to configure Spring AOP. The next two examples show the
minimal definition required for a not-very-useful aspect.
-The first of the two example shows a regular bean definition in the application context that points to a bean class that has
-the `@Aspect` annotation:
+The first of the two example shows a regular bean definition in the application
+context that points to a bean class that has the `@Aspect` annotation:
[source,xml,indent=0]
[subs="verbatim,quotes"]
@@ -284,8 +282,8 @@ the `@Aspect` annotation:
----
-The second of the two examples shows the `NotVeryUsefulAspect` class definition, which is annotated with
-the `org.aspectj.lang.annotation.Aspect` annotation;
+The second of the two examples shows the `NotVeryUsefulAspect` class definition,
+which is annotated with the `org.aspectj.lang.annotation.Aspect` annotation;
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -413,7 +411,7 @@ If a pointcut is strictly meant to be public-only, even in a CGLIB proxy scenari
potential non-public interactions through proxies, it needs to be defined accordingly.
If your interception needs include method calls or even constructors within the target
-class, consider the use of Spring-driven <> instead
+class, consider the use of Spring-driven <> instead
of Spring's proxy-based AOP framework. This constitutes a different mode of AOP usage
with different characteristics, so be sure to make yourself familiar with weaving
before making a decision.
@@ -1032,8 +1030,8 @@ taken by Spring is simpler and a better match to its proxy-based, execution-only
semantics. You only need to be aware of this difference if you compile @AspectJ
aspects written for Spring and use `proceed` with arguments with the AspectJ compiler
and weaver. There is a way to write such aspects that is 100% compatible across both
-Spring AOP and AspectJ, and this is discussed in the <>.
+Spring AOP and AspectJ, and this is discussed in the
+<>.
The following example shows how to use around advice:
@@ -1551,8 +1549,7 @@ of advice parameters.
To use the aop namespace tags described in this section, you need to import the
`spring-aop` schema, as described in <>.
-See <>
+XML Schema-based configuration>>. See <>
for how to import the tags in the `aop` namespace.
Within your Spring configurations, all aspect and advisor elements must be placed within
@@ -1561,10 +1558,11 @@ application context configuration). An `` element can contain pointc
advisor, and aspect elements (note that these must be declared in that order).
WARNING: The `` style of configuration makes heavy use of Spring's
-<> mechanism. This can cause issues (such as advice not
-being woven) if you already use explicit auto-proxying through the use of
-`BeanNameAutoProxyCreator` or something similar. The recommended usage pattern is to use either
-only the `` style or only the `AutoProxyCreator` style and never mix them.
+<> mechanism. This can cause issues (such as advice
+not being woven) if you already use explicit auto-proxying through the use of
+`BeanNameAutoProxyCreator` or something similar. The recommended usage pattern is to
+use either only the `` style or only the `AutoProxyCreator` style and
+never mix them.
@@ -1618,10 +1616,9 @@ be defined as follows:
----
Note that the pointcut expression itself is using the same AspectJ pointcut expression
-language as described in <>. If you use the schema based
-declaration style, you can refer to named pointcuts defined in types
-(@Aspects) within the pointcut expression. Another way of defining the above pointcut
-would be as follows:
+language as described in <>. If you use the schema based declaration
+style, you can refer to named pointcuts defined in types (@Aspects) within the
+pointcut expression. Another way of defining the above pointcut would be as follows:
[source,xml,indent=0]
[subs="verbatim,quotes"]
@@ -2413,11 +2410,11 @@ The downside of the XML approach is that you cannot define the
The @AspectJ style supports additional instantiation models and richer pointcut
composition. It has the advantage of keeping the aspect as a modular unit. It also has
-the advantage that the @AspectJ aspects can be understood (and thus consumed) both by Spring
-AOP and by AspectJ. So, if you later decide you need the capabilities of AspectJ to
-implement additional requirements, you can easily migrate to an AspectJ-based
-approach. On balance, the Spring team prefers the @AspectJ style whenever you have aspects
-that do more than simple configuration of enterprise services.
+the advantage that the @AspectJ aspects can be understood (and thus consumed) both by
+Spring AOP and by AspectJ. So, if you later decide you need the capabilities of AspectJ
+to implement additional requirements, you can easily migrate to a classic AspectJ setup.
+On balance, the Spring team prefers the @AspectJ style for custom aspects beyond simple
+configuration of enterprise services.
@@ -2426,10 +2423,9 @@ that do more than simple configuration of enterprise services.
== Mixing Aspect Types
It is perfectly possible to mix @AspectJ style aspects by using the auto-proxying support,
-schema-defined `` aspects, `` declared advisors, and even
-proxies and interceptors defined with the Spring 1.2 style in the same configuration.
-All of these are implemented by using the same underlying support mechanism and can
-co-exist without any difficulty.
+schema-defined `` aspects, `` declared advisors, and even proxies
+and interceptors in other styles in the same configuration. All of these are implemented
+by using the same underlying support mechanism and can co-exist without any difficulty.
@@ -2438,29 +2434,26 @@ co-exist without any difficulty.
== Proxying Mechanisms
Spring AOP uses either JDK dynamic proxies or CGLIB to create the proxy for a given
-target object. (JDK dynamic proxies are preferred whenever you have a choice).
+target object. JDK dynamic proxies are built into the JDK, whereas CGLIB is a common
+open-source class definition library (repackaged into `spring-core`).
If the target object to be proxied implements at least one interface, a JDK dynamic
-proxy is used. All of the interfaces implemented by the target type are
-proxied. If the target object does not implement any interfaces, a CGLIB proxy is
-created.
+proxy is used. All of the interfaces implemented by the target type are proxied.
+If the target object does not implement any interfaces, a CGLIB proxy is created.
If you want to force the use of CGLIB proxying (for example, to proxy every method
-defined for the target object, not only those implemented by its interfaces), you can do
-so. However, you should consider the following issues:
-
-* `final` methods cannot be advised, as they cannot be overridden.
-* As of Spring 3.2, it is no longer necessary to add CGLIB to your project classpath, as
- CGLIB classes are repackaged under `org.springframework` and included directly in the
- spring-core JAR. This means that CGLIB-based proxy support "`just works`", in the same
- way that JDK dynamic proxies always have.
-* As of Spring 4.0, the constructor of your proxied object is NOT called twice
- any more, since the CGLIB proxy instance is created through Objenesis. Only if your
- JVM does not allow for constructor bypassing, you might see double invocations and
+defined for the target object, not only those implemented by its interfaces),
+you can do so. However, you should consider the following issues:
+
+* With CGLIB, `final` methods cannot be advised, as they cannot be overridden in
+ runtime-generated subclasses.
+* As of Spring 4.0, the constructor of your proxied object is NOT called twice anymore,
+ since the CGLIB proxy instance is created through Objenesis. Only if your JVM does
+ not allow for constructor bypassing, you might see double invocations and
corresponding debug log entries from Spring's AOP support.
-To force the use of CGLIB proxies, set the value of the `proxy-target-class` attribute of
-the `` element to true, as follows:
+To force the use of CGLIB proxies, set the value of the `proxy-target-class` attribute
+of the `` element to true, as follows:
[source,xml,indent=0]
[subs="verbatim,quotes"]
@@ -2471,8 +2464,8 @@ the `` element to true, as follows:
----
To force CGLIB proxying when you use the @AspectJ auto-proxy support, set the
-`proxy-target-class` attribute of the `` element to `true`, as
-follows:
+`proxy-target-class` attribute of the `` element to `true`,
+as follows:
[source,xml,indent=0]
[subs="verbatim,quotes"]
@@ -2533,9 +2526,7 @@ image::images/aop-proxy-plain-pojo-call.png[]
public class Main {
public static void main(String[] args) {
-
Pojo pojo = new SimplePojo();
-
// this is a direct method call on the 'pojo' reference
pojo.foo();
}
@@ -2553,36 +2544,33 @@ image::images/aop-proxy-call.png[]
public class Main {
public static void main(String[] args) {
-
ProxyFactory factory = new ProxyFactory(new SimplePojo());
factory.addInterface(Pojo.class);
factory.addAdvice(new RetryAdvice());
Pojo pojo = (Pojo) factory.getProxy();
-
// this is a method call on the proxy!
pojo.foo();
}
}
----
-The key thing to understand here is that the client code inside the `main(..)` method of the
-`Main` class has a reference to the proxy. This means that method calls on that
-object reference are calls on the proxy. As a result, the proxy can
-delegate to all of the interceptors (advice) that are relevant to that particular method
-call. However, once the call has finally reached the target object (the `SimplePojo`,
-reference in this case), any method calls that it may make on itself, such as
-`this.bar()` or `this.foo()`, are going to be invoked against the `this` reference,
-and not the proxy. This has important implications. It means that self-invocation is
-not going to result in the advice associated with a method invocation getting a
-chance to execute.
+The key thing to understand here is that the client code inside the `main(..)` method
+of the `Main` class has a reference to the proxy. This means that method calls on that
+object reference are calls on the proxy. As a result, the proxy can delegate to all of
+the interceptors (advice) that are relevant to that particular method call. However,
+once the call has finally reached the target object (the `SimplePojo`, reference in
+this case), any method calls that it may make on itself, such as `this.bar()` or
+`this.foo()`, are going to be invoked against the `this` reference, and not the proxy.
+This has important implications. It means that self-invocation is not going to result
+in the advice associated with a method invocation getting a chance to execute.
-Okay, so what is to be done about this? The best approach (the term, "`best,`" is used loosely
-here) is to refactor your code such that the self-invocation does not happen.
+Okay, so what is to be done about this? The best approach (the term, "`best,`" is used
+loosely here) is to refactor your code such that the self-invocation does not happen.
This does entail some work on your part, but it is the best, least-invasive approach.
-The next approach is absolutely horrendous, and we hesitate to point it out,
-precisely because it is so horrendous. You can (painful as it is to us) totally tie the logic within
-your class to Spring AOP, as the following example shows:
+The next approach is absolutely horrendous, and we hesitate to point it out, precisely
+because it is so horrendous. You can (painful as it is to us) totally tie the logic
+within your class to Spring AOP, as the following example shows:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -2611,14 +2599,12 @@ following example shows:
public class Main {
public static void main(String[] args) {
-
ProxyFactory factory = new ProxyFactory(new SimplePojo());
factory.adddInterface(Pojo.class);
factory.addAdvice(new RetryAdvice());
factory.setExposeProxy(true);
Pojo pojo = (Pojo) factory.getProxy();
-
// this is a method call on the proxy!
pojo.foo();
}
@@ -2634,11 +2620,11 @@ it is not a proxy-based AOP framework.
[[aop-aspectj-programmatic]]
== Programmatic Creation of @AspectJ Proxies
-In addition to declaring aspects in your configuration by using either `` or
-``, it is also possible to programmatically create proxies that
-advise target objects. For the full details of Spring's AOP API, see the <>.
-Here, we want to focus on the ability to automatically create proxies by using @AspectJ
-aspects.
+In addition to declaring aspects in your configuration by using either ``
+or ``, it is also possible to programmatically create proxies
+that advise target objects. For the full details of Spring's AOP API, see the
+<>. Here, we want to focus on the ability to automatically
+create proxies by using @AspectJ aspects.
You can use the `org.springframework.aop.aspectj.annotation.AspectJProxyFactory` class
to create a proxy for a target object that is advised by one or more @AspectJ aspects.
@@ -2748,13 +2734,12 @@ Spring now looks for a bean definition named `account` and uses that as the
definition to configure new `Account` instances.
You can also use autowiring to avoid having to specify a dedicated bean definition at
-all. To have Spring apply autowiring, use the `autowire` property of the
-`@Configurable` annotation. You can specify either `@Configurable(autowire=Autowire.BY_TYPE)` or
+all. To have Spring apply autowiring, use the `autowire` property of the `@Configurable`
+annotation. You can specify either `@Configurable(autowire=Autowire.BY_TYPE)` or
`@Configurable(autowire=Autowire.BY_NAME` for autowiring by type or by name,
-respectively. As an alternative, as of Spring 2.5, it is preferable to specify explicit,
-annotation-driven dependency injection for your `@Configurable` beans by using
-`@Autowired` or `@Inject` at the field or method level (see <>
-for further details).
+respectively. As an alternative, it is preferable to specify explicit, annotation-driven
+dependency injection for your `@Configurable` beans through `@Autowired` or `@Inject`
+at the field or method level (see <> for further details).
Finally, you can enable Spring dependency checking for the object references in the newly
created and configured object by using the `dependencyCheck` attribute (for example,
@@ -2764,13 +2749,13 @@ are not primitives or collections) have been set.
Note that using the annotation on its own does nothing. It is the
`AnnotationBeanConfigurerAspect` in `spring-aspects.jar` that acts on the presence of
-the annotation. In essence, the aspect says, "`after returning from the initialization of a
-new object of a type annotated with `@Configurable`, configure the newly created object
+the annotation. In essence, the aspect says, "`after returning from the initialization of
+a new object of a type annotated with `@Configurable`, configure the newly created object
using Spring in accordance with the properties of the annotation`". In this context,
-"`initialization`" refers to newly instantiated objects (for example, objects instantiated with
-the `new` operator) as well as to `Serializable` objects that are undergoing
+"`initialization`" refers to newly instantiated objects (for example, objects instantiated
+with the `new` operator) as well as to `Serializable` objects that are undergoing
deserialization (for example, through
-http://docs.oracle.com/javase/6/docs/api/java/io/Serializable.html[readResolve()]).
+http://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html[readResolve()]).
[NOTE]
=====
@@ -2786,7 +2771,7 @@ available for use in the body of the constructors, you need to define this on th
[source,java,indent=0]
[subs="verbatim,quotes"]
----
- @Configurable(preConstruction=true)
+ @Configurable(preConstruction = true)
----
You can find more information about the language semantics of the various pointcut
@@ -2811,7 +2796,6 @@ use Java-based configuration, you can add `@EnableSpringConfigured` to any
@Configuration
@EnableSpringConfigured
public class AppConfig {
-
}
----
@@ -2943,7 +2927,6 @@ fully qualified class names:
initialization(new(..)) &&
SystemArchitecture.inDomainModel() &&
this(beanInstance);
-
}
----
@@ -3027,14 +3010,12 @@ per-`ClassLoader` basis, which is more fine-grained and which can make more
sense in a 'single-JVM-multiple-application' environment (such as is found in a typical
application server environment).
-Further, <>, this support enables
+Further, <>, this support enables
load-time weaving without making any modifications to the application server's launch
-script that is needed to add `-javaagent:path/to/aspectjweaver.jar` or (as we
-describe later in this section)
-`-javaagent:path/to/org.springframework.instrument-{version}.jar` (previously named
-`spring-agent.jar`). Developers modify one or more files that form the
-application context to enable load-time weaving instead of relying on administrators who
-typically are in charge of the deployment configuration, such as the launch script.
+script that is needed to add `-javaagent:path/to/aspectjweaver.jar` or (as we describe
+later in this section) `-javaagent:path/to/spring-instrument.jar`. Developers configure
+the application context to enable load-time weaving instead of relying on administrators
+who typically are in charge of the deployment configuration, such as the launch script.
Now that the sales pitch is over, let us first walk through a quick example of AspectJ
LTW that uses Spring, followed by detailed specifics about elements introduced in the
@@ -3046,18 +3027,18 @@ https://github.com/spring-projects/spring-petclinic[Petclinic sample application
==== A First Example
Assume that you are an application developer who has been tasked with diagnosing
-the cause of some performance problems in a system. Rather than break out a profiling
-tool, we are going to switch on a simple profiling aspect that lets us
-quickly get some performance metrics. We can then apply a finer-grained
-profiling tool to that specific area immediately afterwards.
+the cause of some performance problems in a system. Rather than break out a
+profiling tool, we are going to switch on a simple profiling aspect that lets us
+quickly get some performance metrics. We can then apply a finer-grained profiling
+tool to that specific area immediately afterwards.
-NOTE: The example presented here uses XML configuration. You can also
-configure and use @AspectJ with <>.
-Specifically, you can use the `@EnableLoadTimeWeaving` annotation as an alternative to
-` ` (see <> for details).
+NOTE: The example presented here uses XML configuration. You can also configure and
+use @AspectJ with <>. Specifically, you can use the
+`@EnableLoadTimeWeaving` annotation as an alternative to ` `
+(see <> for details).
-The following example shows the profiling aspect, which is not fancy -- it is a time-based
-profiler that uses the @AspectJ-style of aspect declaration:
+The following example shows the profiling aspect, which is not fancy.
+It is a time-based profiler that uses the @AspectJ-style of aspect declaration:
[source,java,indent=0]
[subs="verbatim"]
@@ -3091,10 +3072,10 @@ profiler that uses the @AspectJ-style of aspect declaration:
}
----
-We also need to create an `META-INF/aop.xml` file, to inform the AspectJ weaver
-that we want to weave our `ProfilingAspect` into our classes. This file convention,
-namely the presence of a file (or files) on the Java classpath called
-`META-INF/aop.xml` is standard AspectJ. The following example shows the `aop.xml` file:
+We also need to create an `META-INF/aop.xml` file, to inform the AspectJ weaver that
+we want to weave our `ProfilingAspect` into our classes. This file convention, namely
+the presence of a file (or files) on the Java classpath called `META-INF/aop.xml` is
+standard AspectJ. The following example shows the `aop.xml` file:
[source,xml,indent=0]
[subs="verbatim,quotes"]
@@ -3115,12 +3096,13 @@ namely the presence of a file (or files) on the Java classpath called
----
-Now we can move on to the Spring-specific portion of the configuration. We need to configure a
-`LoadTimeWeaver` (explained later). This load-time
-weaver is the essential component responsible for weaving the aspect configuration in
-one or more `META-INF/aop.xml` files into the classes in your application. The good
-thing is that it does not require a lot of configuration (there
-are some more options that you can specify, but these are detailed later), as can be seen in the following example:
+Now we can move on to the Spring-specific portion of the configuration. We need
+to configure a `LoadTimeWeaver` (explained later). This load-time weaver is the
+essential component responsible for weaving the aspect configuration in one or
+more `META-INF/aop.xml` files into the classes in your application. The good
+thing is that it does not require a lot of configuration (there are some more
+options that you can specify, but these are detailed later), as can be seen in
+the following example:
[source,xml,indent=0]
[subs="verbatim,quotes"]
@@ -3145,8 +3127,8 @@ are some more options that you can specify, but these are detailed later), as ca
----
Now that all the required artifacts (the aspect, the `META-INF/aop.xml`
-file, and the Spring configuration) are in place, we can create the following driver class with a
-`main(..)` method to demonstrate the LTW in action:
+file, and the Spring configuration) are in place, we can create the following
+driver class with a `main(..)` method to demonstrate the LTW in action:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -3158,11 +3140,10 @@ file, and the Spring configuration) are in place, we can create the following dr
public final class Main {
public static void main(String[] args) {
-
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml", Main.class);
- EntitlementCalculationService entitlementCalculationService
- = (EntitlementCalculationService) ctx.getBean("entitlementCalculationService");
+ EntitlementCalculationService entitlementCalculationService =
+ (EntitlementCalculationService) ctx.getBean("entitlementCalculationService");
// the profiling aspect is 'woven' around this method execution
entitlementCalculationService.calculateEntitlement();
@@ -3172,8 +3153,8 @@ file, and the Spring configuration) are in place, we can create the following dr
We have one last thing to do. The introduction to this section did say that one could
switch on LTW selectively on a per-`ClassLoader` basis with Spring, and this is true.
-However, for this example, we use a Java agent (supplied with Spring)
-to switch on the LTW. We use the following command to run the `Main` class shown earlier:
+However, for this example, we use a Java agent (supplied with Spring) to switch on LTW.
+We use the following command to run the `Main` class shown earlier:
[literal]
[subs="verbatim,quotes"]
@@ -3182,7 +3163,7 @@ java -javaagent:C:/projects/foo/lib/global/spring-instrument.jar foo.Main
----
The `-javaagent` is a flag for specifying and enabling
-http://docs.oracle.com/javase/6/docs/api/java/lang/instrument/package-summary.html[agents
+http://docs.oracle.com/javase/8/docs/api/java/lang/instrument/package-summary.html[agents
to instrument programs that run on the JVM]. The Spring Framework ships with such an
agent, the `InstrumentationSavingAgent`, which is packaged in the
`spring-instrument.jar` that was supplied as the value of the `-javaagent` argument in
@@ -3220,11 +3201,10 @@ result:
public final class Main {
public static void main(String[] args) {
-
new ClassPathXmlApplicationContext("beans.xml", Main.class);
EntitlementCalculationService entitlementCalculationService =
- new StubEntitlementCalculationService();
+ new StubEntitlementCalculationService();
// the profiling aspect will be 'woven' around this method execution
entitlementCalculationService.calculateEntitlement();
@@ -3261,8 +3241,9 @@ Furthermore, the compiled aspect classes need to be available on the classpath.
The AspectJ LTW infrastructure is configured by using one or more `META-INF/aop.xml`
files that are on the Java classpath (either directly or, more typically, in jar files).
-The structure and contents of this file is detailed in the LTW part http://www.eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html[AspectJ reference
-documentation]. Because the aop.xml file is 100% AspectJ, we do not describe it further here.
+The structure and contents of this file is detailed in the LTW part of the
+http://www.eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html[AspectJ reference
+documentation]. Because the `aop.xml` file is 100% AspectJ, we do not describe it further here.
[[aop-aj-ltw-libraries]]
@@ -3271,10 +3252,10 @@ documentation]. Because the aop.xml file is 100% AspectJ, we do not describe it
At minimum, you need the following libraries to use the Spring Framework's support
for AspectJ LTW:
-* `spring-aop.jar` (version 2.5 or later, plus all mandatory dependencies)
-* `aspectjweaver.jar` (version 1.6.8 or later)
+* `spring-aop.jar`
+* `aspectjweaver.jar`
-If you use the <>, you also need:
* `spring-instrument.jar`
@@ -3309,7 +3290,6 @@ which typically is done by using the `@EnableLoadTimeWeaving` annotation, as fol
@Configuration
@EnableLoadTimeWeaving
public class AppConfig {
-
}
----
@@ -3335,50 +3315,50 @@ Alternatively, if you prefer XML-based configuration, use the
----
-The preceding configuration automatically defines and registers a number of LTW-specific infrastructure
-beans, such as a `LoadTimeWeaver` and an `AspectJWeavingEnabler`, for you.
+The preceding configuration automatically defines and registers a number of LTW-specific
+infrastructure beans, such as a `LoadTimeWeaver` and an `AspectJWeavingEnabler`, for you.
The default `LoadTimeWeaver` is the `DefaultContextLoadTimeWeaver` class, which attempts
-to decorate an automatically detected `LoadTimeWeaver`. The exact type of
-`LoadTimeWeaver` that is "`automatically detected`" is dependent upon your runtime
-environment. The following table summarizes various `LoadTimeWeaver` implementations:
+to decorate an automatically detected `LoadTimeWeaver`. The exact type of `LoadTimeWeaver`
+that is "`automatically detected`" is dependent upon your runtime environment.
+The following table summarizes various `LoadTimeWeaver` implementations:
[[aop-aj-ltw-spring-env-impls]]
.DefaultContextLoadTimeWeaver LoadTimeWeavers
|===
| Runtime Environment| `LoadTimeWeaver` implementation
-| Running in Oracle's
- http://www.oracle.com/technetwork/middleware/weblogic/overview/index-085209.html[WebLogic]
-| `WebLogicLoadTimeWeaver`
-
-| Running in Oracle's http://glassfish.dev.java.net/[GlassFish]
-| `GlassFishLoadTimeWeaver`
-
| Running in http://tomcat.apache.org/[Apache Tomcat]
| `TomcatLoadTimeWeaver`
+| Running in http://glassfish.dev.java.net/[GlassFish] (limited to EAR deployments)
+| `GlassFishLoadTimeWeaver`
+
| Running in Red Hat's http://www.jboss.org/jbossas/[JBoss AS] or http://www.wildfly.org/[WildFly]
| `JBossLoadTimeWeaver`
| Running in IBM's http://www-01.ibm.com/software/webservers/appserv/was/[WebSphere]
| `WebSphereLoadTimeWeaver`
-| JVM started with Spring `InstrumentationSavingAgent` (`java
- -javaagent:path/to/spring-instrument.jar`)
+| Running in Oracle's
+ http://www.oracle.com/technetwork/middleware/weblogic/overview/index-085209.html[WebLogic]
+| `WebLogicLoadTimeWeaver`
+
+| JVM started with Spring `InstrumentationSavingAgent`
+ (`java -javaagent:path/to/spring-instrument.jar`)
| `InstrumentationLoadTimeWeaver`
-| Fallback, expecting the underlying ClassLoader to follow common conventions (for example
- applicable to `TomcatInstrumentableClassLoader` and http://www.caucho.com/[Resin])
+| Fallback, expecting the underlying ClassLoader to follow common conventions
+ (namely `addTransformer` and optionally a `getThrowawayClassLoader` method)
| `ReflectiveLoadTimeWeaver`
|===
-Note that the table lists only the `LoadTimeWeavers` that are autodetected when you use the
-`DefaultContextLoadTimeWeaver`. You can specify exactly which
-`LoadTimeWeaver` implementation to use.
+Note that the table lists only the `LoadTimeWeavers` that are autodetected when you
+use the `DefaultContextLoadTimeWeaver`. You can specify exactly which `LoadTimeWeaver`
+implementation to use.
To specify a specific `LoadTimeWeaver` with Java configuration, implement the
-`LoadTimeWeavingConfigurer` interface and override the `getLoadTimeWeaver()` method. The
-following example specifies a `ReflectiveLoadTimeWeaver`:
+`LoadTimeWeavingConfigurer` interface and override the `getLoadTimeWeaver()` method.
+The following example specifies a `ReflectiveLoadTimeWeaver`:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -3426,10 +3406,9 @@ the `org.aspectj.weaver.loadtime` package) class. See the class-level javadoc of
`ClassPreProcessorAgentAdapter` class for further details, because the specifics of how
the weaving is actually effected is beyond the scope of this document.
-There is one final attribute of the configuration left to discuss: the
-`aspectjWeaving` attribute (or `aspectj-weaving` if you use XML). This
-attribute controls whether LTW is enabled or not.
-It accepts one of three possible values, with the default value being
+There is one final attribute of the configuration left to discuss: the `aspectjWeaving`
+attribute (or `aspectj-weaving` if you use XML). This attribute controls whether LTW
+is enabled or not. It accepts one of three possible values, with the default value being
`autodetect` if the attribute is not present. The following table summarizes the three
possible values:
@@ -3460,69 +3439,17 @@ This last section contains any additional settings and configuration that you ne
when you use Spring's LTW support in environments such as application servers and web
containers.
-[[aop-aj-ltw-environment-tomcat]]
-===== Tomcat
-
-Historically, http://tomcat.apache.org/[Apache Tomcat]'s default class loader did not
-support class transformation, which is why Spring provides an enhanced implementation
-that addresses this need. Named `TomcatInstrumentableClassLoader`, the loader works on
-Tomcat 6.0 and above.
+[[aop-aj-ltw-environments-tomcat-jboss-etc]]
+===== Tomcat, JBoss, WebSphere, WebLogic
-TIP: Do not define `TomcatInstrumentableClassLoader` on Tomcat 8.0 and higher.
-Instead, let Spring automatically use Tomcat's new native `InstrumentableClassLoader`
-facility through the `TomcatLoadTimeWeaver` strategy.
+Tomcat, JBoss/WildFly, IBM WebSphere Application Server and Oracle WebLogic Server all
+provide a general app `ClassLoader` that is capable of local instrumentation. Spring's
+native LTW may leverage those ClassLoader implementations to provide AspectJ weaving.
+You can simply enable load-time weaving, as <>.
+Specifically, you do not need to modify the JVM launch script to add
+`-javaagent:path/to/spring-instrument.jar`.
-If you still need to use `TomcatInstrumentableClassLoader`, you can register it
-individually for each web application as follows:
-
-. Copy `org.springframework.instrument.tomcat.jar` into `$CATALINA_HOME/lib`, where
- `$CATALINA_HOME` represents the root of the Tomcat installation
-. Instruct Tomcat to use the custom class loader (instead of the default) by editing the
- web application context file, as the following example shows:
-
-[source,xml,indent=0]
-[subs="verbatim,quotes"]
-----
-
-
-
-----
-
-Apache Tomcat 6.0+ supports several context locations:
-
-* Server configuration file: `$CATALINA_HOME/conf/server.xml`
-* Default context configuration: `$CATALINA_HOME/conf/context.xml`, which affects all
- deployed web applications
-* A per-web application configuration, which can be deployed either on the server-side at
- `$CATALINA_HOME/conf/[enginename]/[hostname]/[webapp]-context.xml` or embedded
- inside the web-app archive at `META-INF/context.xml`
-
-For efficiency, we recommend the embedded per-web application configuration style, because it
-impacts only applications that use the custom class loader and does not require any
-changes to the server configuration. See the Tomcat 6.0.x
-http://tomcat.apache.org/tomcat-6.0-doc/config/context.html[documentation] for more
-details about available context locations.
-
-Alternatively, consider using the Spring-provided generic VM agent, to be specified
-in Tomcat's launch script (described earlier in this section). This makes instrumentation available to all
-deployed web applications, no matter the `ClassLoader` on which they happen to run.
-
-[[aop-aj-ltw-environments-weblogic-oc4j-resin-glassfish-jboss]]
-===== WebLogic, WebSphere, Resin, GlassFish, and JBoss
-
-Recent versions of WebLogic Server (version 10 and above), IBM WebSphere Application
-Server (version 7 and above), Resin (version 3.1 and above), and JBoss (version 6.x or above) provide a
-`ClassLoader` that is capable of local instrumentation. Spring's native LTW leverages such
-ClassLoader implementations to enable AspectJ weaving. You can enable LTW by activating
-load-time weaving, as <>. Specifically, you do not need to modify the
-launch script to add `-javaagent:path/to/spring-instrument.jar`.
-
-Note that the GlassFish instrumentation-capable `ClassLoader` is available only in its EAR
-environment. For GlassFish web applications, follow the Tomcat setup instructions
-<>.
-
-Note that, on JBoss 6.x, you need to disable the app server scanning to prevent it from
+Note that on JBoss, you may need to disable the app server scanning to prevent it from
loading the classes before the application actually starts. A quick workaround is to add
to your artifact a file named `WEB-INF/jboss-scanning.xml` with the following content:
@@ -3532,31 +3459,28 @@ to your artifact a file named `WEB-INF/jboss-scanning.xml` with the following co
----
-[[aop-aj-ltw-environment-generic]]
+[[aop-aj-ltw-environments-generic]]
===== Generic Java Applications
-When class instrumentation is required in environments that do not support or are not
-supported by the existing `LoadTimeWeaver` implementations, a JDK agent can be the only
-solution. For such cases, Spring provides `InstrumentationLoadTimeWeaver`, which
-requires a Spring-specific (but very general) VM agent,
-`org.springframework.instrument-{version}.jar` (previously named `spring-agent.jar`).
+When class instrumentation is required in environments that are not supported by
+specific `LoadTimeWeaver` implementations, a JVM agent is the general solution.
+For such cases, Spring provides `InstrumentationLoadTimeWeaver` which requires a
+Spring-specific (but very general) JVM agent, `spring-instrument.jar`, autodetected
+by common `@EnableLoadTimeWeaving` and ` ` setups.
-To use it, you must start the virtual machine with the Spring agent by supplying the
-following JVM options:
+To use it, you must start the virtual machine with the Spring agent by supplying
+the following JVM options:
[literal]
[subs="verbatim,quotes"]
----
--javaagent:/path/to/org.springframework.instrument-{version}.jar
+-javaagent:/path/to/spring-instrument.jar
----
-Note that this requires modification of the VM launch script, which may prevent you from
-using this in application server environments (depending on your operation policies).
-Additionally, the JDK agent instruments the entire VM, which can be expensive.
-
-For performance reasons, we recommend that you use this configuration only if your target
-environment (such as http://www.eclipse.org/jetty/[Jetty]) does not have (or does not
-support) a dedicated LTW.
+Note that this requires modification of the JVM launch script, which may prevent you
+from using this in application server environments (depending on your server and your
+operation policies). That said, for one-app-per-JVM deployments such as standalone
+Spring Boot applications, you typically control the entire JVM setup in any case.
diff --git a/src/docs/asciidoc/core/core-appendix.adoc b/src/docs/asciidoc/core/core-appendix.adoc
index 4a776244b96..275004e1cd2 100644
--- a/src/docs/asciidoc/core/core-appendix.adoc
+++ b/src/docs/asciidoc/core/core-appendix.adoc
@@ -5,6 +5,7 @@
+
[[xsd-schemas]]
== XML Schemas
@@ -36,7 +37,6 @@ correct schema so that the tags in the `util` namespace are available to you):
----
-
[[xsd-schemas-util-constant]]
==== Using ` `
@@ -72,8 +72,6 @@ developer's intent ("`inject this constant value`"), and it reads better:
----
-
-
[[xsd-schemas-util-frfb]]
===== Setting a Bean Property or Constructor Argument from a Field Value
@@ -127,10 +125,9 @@ described in the API documentation for the
class.
Injecting enumeration values into beans as either property or constructor arguments is
-easy to do in Spring. You do not actually have to do anything or know
-anything about the Spring internals (or even about classes such as the
-`FieldRetrievingFactoryBean`). The following example enumeration shows how easy injecting an
-enum value is:
+easy to do in Spring. You do not actually have to do anything or know anything about
+the Spring internals (or even about classes such as the `FieldRetrievingFactoryBean`).
+The following example enumeration shows how easy injecting an enum value is:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -170,7 +167,6 @@ Now consider the following setter of type `PersistenceContextType` and the corre
----
-
[[xsd-schemas-util-property-path]]
==== Using ` `
@@ -327,7 +323,6 @@ The following example uses a `util:properties` element to make a more concise re
----
-
[[xsd-schemas-util-list]]
==== Using ` `
@@ -386,7 +381,6 @@ following configuration:
If no `list-class` attribute is supplied, the container chooses a `List` implementation.
-
[[xsd-schemas-util-map]]
==== Using ` `
@@ -445,7 +439,6 @@ following configuration:
If no `'map-class'` attribute is supplied, the container chooses a `Map` implementation.
-
[[xsd-schemas-util-set]]
==== Using ` `
@@ -558,69 +551,64 @@ available to you:
----
-
[[xsd-schemas-context-pphc]]
==== Using ` `
This element activates the replacement of `${...}` placeholders, which are resolved against a
-specified properties file (as a <>). This element
-is a convenience mechanism that sets up a <> for you. If you need more control over the
-`PropertySourcesPlaceholderConfigurer`, you can explicitly define one yourself.
-
+specified properties file (as a <>). This element is
+a convenience mechanism that sets up a <> for you. If you need more control over the
+`PropertyPlaceholderConfigurer`, you can explicitly define one yourself.
[[xsd-schemas-context-ac]]
==== Using ` `
-This element activates the Spring infrastructure to detect annotations in bean
-classes:
+This element activates the Spring infrastructure to detect annotations in bean classes:
-* Spring's <> and
-<>
-* JSR 250's `@PostConstruct`,
-`@PreDestroy` and `@Resource` (if available)
-* JPA's `@PersistenceContext` and
-`@PersistenceUnit` (if available).
+* Spring's <> model
+* <> and `@Value`
+* JSR-250's `@Resource`, `@PostConstruct` and `@PreDestroy` (if available)
+* JPA's `@PersistenceContext` and `@PersistenceUnit` (if available)
+* Spring's <>
-Alternatively, you can choose to explicitly activate the
-individual `BeanPostProcessors` for those annotations.
+Alternatively, you can choose to explicitly activate the individual `BeanPostProcessors`
+for those annotations.
NOTE: This element does not activate processing of Spring's
-<> annotation. You can use the
-< `>> element for that purpose.
-
+<> annotation;
+you can use the < `>>
+element for that purpose. Similarly, Spring's
+<> need to be explicitly
+<> as well.
[[xsd-schemas-context-component-scan]]
==== Using ` `
-This element is detailed in <>.
-
+This element is detailed in the section on <>.
[[xsd-schemas-context-ltw]]
==== Using ` `
-This element is detailed in <>.
-
+This element is detailed in the section on <>.
[[xsd-schemas-context-sc]]
==== Using ` `
-This element is detailed in <>.
-
+This element is detailed in the section on <>.
[[xsd-schemas-context-mbe]]
==== Using ` `
-This element is detailed in <>.
+This element is detailed in the section on <>.
@@ -630,8 +618,8 @@ Configuring annotation based MBean export>>.
Last but not least, we have the elements in the `beans` schema. These elements
have been in Spring since the very dawn of the framework. Examples of the various elements
in the `beans` schema are not shown here because they are quite comprehensively covered
-in <>
-(and, indeed, in that entire <>).
+in <>
+(and, indeed, in that entire <>).
Note that you can add zero or more key-value pairs to ` ` XML definitions.
What, if anything, is done with this extra metadata is totally up to your own custom
@@ -660,10 +648,9 @@ as it stands).
----
<1> This is the example `meta` element
+In the case of the preceding example, you could assume that there is some logic that consumes
+the bean definition and sets up some caching infrastructure that uses the supplied metadata.
-In the case of the preceding example, you could assume that there is some logic that
-consumes the bean definition and sets up some caching infrastructure that uses the supplied
-metadata.
@@ -683,11 +670,11 @@ Spring distribution, you should first read the appendix entitled <>.
To create new XML configuration extensions:
-. <> an XML schema to describe your custom element(s).
-. <> a custom `NamespaceHandler` implementation.
-. <> one or more `BeanDefinitionParser` implementations
+. <> an XML schema to describe your custom element(s).
+. <> a custom `NamespaceHandler` implementation.
+. <> one or more `BeanDefinitionParser` implementations
(this is where the real work is done).
-. <> your new artifacts with Spring.
+. <> your new artifacts with Spring.
For a unified example, we create an
XML extension (a custom XML element) that lets us configure objects of the type
@@ -801,7 +788,7 @@ The `NamespaceHandler` interface features three methods:
* `BeanDefinitionHolder decorate(Node, BeanDefinitionHolder, ParserContext)`: Called
when Spring encounters an attribute or nested element of a different namespace.
The decoration of one or more bean definitions is used (for example) with the
- <>.
+ <>.
We start by highlighting a simple example, without using decoration, after which
we show decoration in a somewhat more advanced example.
@@ -889,7 +876,6 @@ the basic grunt work of creating a single `BeanDefinition`.
<2> We supply the `AbstractSingleBeanDefinitionParser` superclass with the type that our
single `BeanDefinition` represents.
-
In this simple case, this is all that we need to do. The creation of our single
`BeanDefinition` is handled by the `AbstractSingleBeanDefinitionParser` superclass, as
is the extraction and setting of the bean definition's unique identifier.
@@ -898,6 +884,7 @@ is the extraction and setting of the bean definition's unique identifier.
[[xsd-custom-registration]]
=== Registering the Handler and the Schema
+
The coding is finished. All that remains to be done is to make the Spring XML
parsing infrastructure aware of our custom element. We do so by registering our custom
`namespaceHandler` and custom XSD file in two special-purpose properties files. These
@@ -907,7 +894,6 @@ XML parsing infrastructure automatically picks up your new extension by consumin
these special properties files, the formats of which are detailed in the next two sections.
-
[[xsd-custom-registration-spring-handlers]]
==== Writing `META-INF/spring.handlers`
@@ -928,7 +914,6 @@ namespace extension and needs to exactly match exactly the value of the `targetN
attribute, as specified in your custom XSD schema.
-
[[xsd-custom-registration-spring-schemas]]
==== Writing 'META-INF/spring.schemas'
@@ -995,7 +980,6 @@ in a Spring XML configuration file:
This section presents some more detailed examples of custom XML extensions.
-
[[xsd-custom-custom-nested]]
==== Nesting Custom Elements within Custom Elements
@@ -1060,7 +1044,6 @@ The following listing shows the `Component` class:
public void setName(String name) {
this.name = name;
}
-
}
----
@@ -1068,7 +1051,6 @@ The typical solution to this issue is to create a custom `FactoryBean` that expo
setter property for the `components` property. The following listing shows such a custom
`FactoryBean`:
-
[source,java,indent=0]
[subs="verbatim,quotes"]
----
@@ -1107,15 +1089,14 @@ setter property for the `components` property. The following listing shows such
public boolean isSingleton() {
return true;
}
-
}
----
-This works nicely, but it exposes a lot of Spring plumbing to the
-end user. What we are going to do is write a custom extension that hides away all of
-this Spring plumbing. If we stick to <>, we start off by creating the XSD schema to define the structure of our
-custom tag, as the following listing shows:
+This works nicely, but it exposes a lot of Spring plumbing to the end user. What we are
+going to do is write a custom extension that hides away all of this Spring plumbing.
+If we stick to <>, we start off
+by creating the XSD schema to define the structure of our custom tag, as the following
+listing shows:
[source,xml,indent=0]
[subs="verbatim,quotes"]
@@ -1141,7 +1122,8 @@ custom tag, as the following listing shows:
----
-Again following <>, we then create a custom `NamespaceHandler`:
+Again following <>,
+we then create a custom `NamespaceHandler`:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -1155,13 +1137,12 @@ Again following <>, we th
public void init() {
registerBeanDefinitionParser("component", new ComponentBeanDefinitionParser());
}
-
}
----
Next up is the custom `BeanDefinitionParser`. Remember that we are creating
-`BeanDefinition` that describes a `ComponentFactoryBean`. The following listing shows our
-custom `BeanDefinitionParser`:
+a `BeanDefinition` that describes a `ComponentFactoryBean`. The following
+listing shows our custom `BeanDefinitionParser` implementation:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -1210,7 +1191,6 @@ custom `BeanDefinitionParser`:
}
factory.addPropertyValue("children", children);
}
-
}
----
@@ -1232,21 +1212,20 @@ http\://www.foo.com/schema/component/component.xsd=com/foo/component.xsd
----
-
[[xsd-custom-custom-just-attributes]]
==== Custom Attributes on "`Normal`" Elements
-Writing your own custom parser and the associated artifacts is not hard. However, it is sometimes
-not the right thing to do. Consider a scenario where you need to add metadata to
-already existing bean definitions. In this case, you certainly do not want to have to
-write your own entire custom extension. Rather, you merely want to add an
-additional attribute to the existing bean definition element.
+Writing your own custom parser and the associated artifacts is not hard. However,
+it is sometimes not the right thing to do. Consider a scenario where you need to
+add metadata to already existing bean definitions. In this case, you certainly
+do not want to have to write your own entire custom extension. Rather, you merely
+want to add an additional attribute to the existing bean definition element.
-By way of another example, suppose that you define a bean
-definition for a service object that (unknown to it) accesses a clustered
-http://jcp.org/en/jsr/detail?id=107[JCache], and you want to ensure that the named
-JCache instance is eagerly started within the surrounding cluster. The following
-listing shows such a definition:
+By way of another example, suppose that you define a bean definition for a
+service object that (unknown to it) accesses a clustered
+http://jcp.org/en/jsr/detail?id=107[JCache], and you want to ensure that the
+named JCache instance is eagerly started within the surrounding cluster.
+The following listing shows such a definition:
[source,xml,indent=0]
[subs="verbatim,quotes"]
@@ -1279,12 +1258,11 @@ JCache-initializing `BeanDefinition`. The following listing shows our `JCacheIni
public void initialize() {
// lots of JCache API calls to initialize the named cache...
}
-
}
----
-Now we can move onto the custom extension. First, we need to author the XSD schema that describes the
-custom attribute, as follows:
+Now we can move onto the custom extension. First, we need to author
+the XSD schema that describes the custom attribute, as follows:
[source,xml,indent=0]
[subs="verbatim,quotes"]
@@ -1320,9 +1298,9 @@ Next, we need to create the associated `NamespaceHandler`, as follows:
}
----
-Next, we need to create the parser. Note that, in this case, because we are going to parse an XML
-attribute, we write a `BeanDefinitionDecorator` rather than a `BeanDefinitionParser`.
-The following listing shows our `BeanDefinitionDecorator`:
+Next, we need to create the parser. Note that, in this case, because we are going to parse
+an XML attribute, we write a `BeanDefinitionDecorator` rather than a `BeanDefinitionParser`.
+The following listing shows our `BeanDefinitionDecorator` implementation:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -1376,7 +1354,6 @@ The following listing shows our `BeanDefinitionDecorator`:
}
return beanName;
}
-
}
----
diff --git a/src/docs/asciidoc/core/core-beans.adoc b/src/docs/asciidoc/core/core-beans.adoc
index 67b947474f4..14932946e27 100644
--- a/src/docs/asciidoc/core/core-beans.adoc
+++ b/src/docs/asciidoc/core/core-beans.adoc
@@ -104,13 +104,13 @@ Spring IoC container.
NOTE: XML-based metadata is not the only allowed form of configuration metadata.
The Spring IoC container itself is totally decoupled from the format in which this
configuration metadata is actually written. These days, many developers choose
-<> for their Spring applications.
+<> for their Spring applications.
For information about using other forms of metadata with the Spring container, see:
* <>: Spring 2.5 introduced
support for annotation-based configuration metadata.
-* <>: Starting with Spring 3.0, many features
+* <>: Starting with Spring 3.0, many features
provided by the Spring JavaConfig project became part of the core Spring Framework.
Thus, you can define beans external to your application classes by using Java rather
than XML files. To use these new features, see the
@@ -257,7 +257,7 @@ XML configuration file represents a logical layer or module in your architecture
You can use the application context constructor to load bean definitions from all these
XML fragments. This constructor takes multiple `Resource` locations, as was shown in the
-<>. Alternatively, use one or more
+<>. Alternatively, use one or more
occurrences of the ` ` element to load bean definitions from another file or
files. The following example shows how to do so:
@@ -974,8 +974,8 @@ example shows:
Keep in mind that, to make this work out of the box, your code must be compiled with the
debug flag enabled so that Spring can look up the parameter name from the constructor.
-If you cannot or do not want to compile your code with the debug flag, you can use
-http://download.oracle.com/javase/6/docs/api/java/beans/ConstructorProperties.html[@ConstructorProperties]
+If you cannot or do not want to compile your code with the debug flag, you can use the
+http://download.oracle.com/javase/8/docs/api/java/beans/ConstructorProperties.html[@ConstructorProperties]
JDK annotation to explicitly name your constructor arguments. The sample class would
then have to look as follows:
@@ -1042,7 +1042,7 @@ load an entire Spring IoC container instance.
****
Since you can mix constructor-based and setter-based DI, it is a good rule of thumb to
use constructors for mandatory dependencies and setter methods or configuration methods
-for optional dependencies. Note that use of the <>
+for optional dependencies. Note that use of the <>
annotation on a setter method can be used to make the property be a required dependency;
however, constructor injection with programmatic validation of arguments is preferable.
@@ -1135,7 +1135,7 @@ to being injected into the dependent bean. This means that, if bean A has a depe
bean B, the Spring IoC container completely configures bean B prior to invoking the
setter method on bean A. In other words, the bean is instantiated (if it is not a
pre-instantiated singleton), its dependencies are set, and the relevant lifecycle
-methods (such as a <>
+methods (such as a <>
or the <>)
are invoked.
@@ -1292,7 +1292,7 @@ do not discuss those details here.
[[beans-factory-properties-detailed]]
=== Dependencies and Configuration in Detail
-As mentioned in the <>, you can define bean
+As mentioned in the <>, you can define bean
properties and constructor arguments as references to other managed beans (collaborators)
or as values defined inline. Spring's XML-based configuration metadata supports
sub-element types within its ` ` and ` ` elements for this
@@ -2077,11 +2077,11 @@ In the latter scenario, you have several options:
* Abandon autowiring in favor of explicit wiring.
* Avoid autowiring for a bean definition by setting its `autowire-candidate` attributes
- to `false`, as described in the <>.
+ to `false`, as described in the <>.
* Designate a single bean definition as the primary candidate by setting the
`primary` attribute of its ` ` element to `true`.
-* Implement the more fine-grained control available
- with annotation-based configuration, as described in <>.
+* Implement the more fine-grained control available with annotation-based configuration,
+ as described in <>.
@@ -2184,7 +2184,7 @@ https://spring.io/blog/2004/08/06/method-injection/[this blog entry].
Lookup method injection is the ability of the container to override methods on
container-managed beans and return the lookup result for another named bean in the
container. The lookup typically involves a prototype bean, as in the scenario described
-in <>. The Spring Framework
+in <>. The Spring Framework
implements this method injection by using bytecode generation from the CGLIB library to
dynamically generate a subclass that overrides the method.
@@ -3326,7 +3326,7 @@ configured with a different method name, then each configured method is executed
order listed after this note. However, if the same method name is configured -- for example,
`init()` for an initialization method -- for more than one of these lifecycle mechanisms,
that method is executed once, as explained in the
-<>.
+<>.
Multiple lifecycle mechanisms configured for the same bean, with different
initialization methods, are called as follows:
@@ -3575,7 +3575,7 @@ init-method.
[[aware-list]]
=== Other `Aware` Interfaces
-Besides `ApplicationContextAware` and `BeanNameAware` (discussed <>),
+Besides `ApplicationContextAware` and `BeanNameAware` (discussed <>),
Spring offers a wide range of `Aware` callback interfaces that let beans indicate to the container
that they require a certain infrastructure dependency. As a general rule, the name indicates the
dependency type. The following table summarizes the most important `Aware` interfaces:
@@ -3680,7 +3680,6 @@ to do so:
----
<1> Note the `parent` attribute.
-
A child bean definition uses the bean class from the parent definition if none is
specified but can also override it. In the latter case, the child bean class must be
compatible with the parent (that is, it must accept the parent's property values).
@@ -4207,7 +4206,7 @@ while others argue that annotated classes are no longer POJOs and, furthermore,
configuration becomes decentralized and harder to control.
No matter the choice, Spring can accommodate both styles and even mix them together.
-It is worth pointing out that through its <> option, Spring lets
+It is worth pointing out that through its <> option, Spring lets
annotations be used in a non-invasive way, without touching the target components
source code and that, in terms of tooling, all configuration styles are supported by the
https://spring.io/tools/sts[Spring Tool Suite].
@@ -4588,7 +4587,7 @@ an `ApplicationContext` object:
[NOTE]
====
-The `@Autowired`, `@Inject`, `@Resource`, and `@Value` annotations are handled by Spring
+The `@Autowired`, `@Inject`, `@Value`, and `@Resource` annotations are handled by Spring
`BeanPostProcessor` implementations. This means that you cannot apply these annotations
within your own `BeanPostProcessor` or `BeanFactoryPostProcessor` types (if any).
These types must be 'wired up' explicitly by using XML or a Spring `@Bean` method.
@@ -5327,9 +5326,9 @@ supported as a marker for automatic exception translation in your persistence la
=== Using Meta-annotations and Composed Annotations
Many of the annotations provided by Spring can be used as meta-annotations in your
-own code. A meta-annotation is an annotation that can be applied to another
-annotation. For example, the `@Service` annotation mentioned <> is meta-annotated with
-`@Component`, as the following example shows:
+own code. A meta-annotation is an annotation that can be applied to another annotation.
+For example, the `@Service` annotation mentioned <>
+is meta-annotated with `@Component`, as the following example shows:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -5482,16 +5481,16 @@ TIP: The use of `` implicitly enables the functionality
====
The scanning of classpath packages requires the presence of corresponding directory
entries in the classpath. When you build JARs with Ant, make sure that you do not
-activate the files-only switch of the JAR task. Also, classpath directories may not
-be exposed based on security policies in some environments -- for example, standalone apps on
+activate the files-only switch of the JAR task. Also, classpath directories may not be
+exposed based on security policies in some environments -- for example, standalone apps on
JDK 1.7.0_45 and higher (which requires 'Trusted-Library' setup in your manifests -- see
http://stackoverflow.com/questions/19394570/java-jre-7u45-breaks-classloader-getresources).
On JDK 9's module path (Jigsaw), Spring's classpath scanning generally works as expected.
However, make sure that your component classes are exported in your `module-info`
descriptors. If you expect Spring to invoke non-public members of your classes, make
-sure that they are 'opened' (that is, that they use an `opens` declaration instead of an `exports`
-declaration in your `module-info` descriptor).
+sure that they are 'opened' (that is, that they use an `opens` declaration instead of an
+`exports` declaration in your `module-info` descriptor).
====
Furthermore, the `AutowiredAnnotationBeanPostProcessor` and
@@ -6466,7 +6465,7 @@ following example shows:
}
----
-NOTE: Remember that `@Configuration` classes are <>
+NOTE: Remember that `@Configuration` classes are <>
with `@Component`, so they are candidates for component-scanning. In the preceding example,
assuming that `AppConfig` is declared within the `com.acme` package (or any package
underneath), it is picked up during the call to `scan()`. Upon `refresh()`, all its `@Bean`
@@ -6544,8 +6543,8 @@ init-param):
`@Bean` is a method-level annotation and a direct analog of the XML ` ` element.
The annotation supports some of the attributes offered by ` `, such as:
-* <>
-* <>
+* <>
+* <>
* <>
* `name`.
@@ -6647,7 +6646,7 @@ parameter, as the following example shows:
----
The resolution mechanism is pretty much identical to constructor-based dependency
-injection. See <> for more details.
+injection. See <> for more details.
[[beans-java-lifecycle-callbacks]]
@@ -6655,17 +6654,17 @@ injection. See <> for more det
Any classes defined with the `@Bean` annotation support the regular lifecycle callbacks
and can use the `@PostConstruct` and `@PreDestroy` annotations from JSR-250. See
-<> for further
+<> for further
details.
-The regular Spring <> callbacks are fully supported as
+The regular Spring <> callbacks are fully supported as
well. If a bean implements `InitializingBean`, `DisposableBean`, or `Lifecycle`, their
respective methods are called by the container.
-The standard set of `*Aware` interfaces (such as <>,
-<>,
-<>,
-<>, and so on) are also fully supported.
+The standard set of `*Aware` interfaces (such as <>,
+<>,
+<>,
+<>, and so on) are also fully supported.
The `@Bean` annotation supports specifying arbitrary initialization and destruction
callback methods, much like Spring XML's `init-method` and `destroy-method` attributes
@@ -6769,7 +6768,7 @@ Spring includes the `@Scope` annotation so that you can specify the scope of a b
You can specify that your beans defined with the `@Bean` annotation should have a
specific scope. You can use any of the standard scopes specified in the
-<> section.
+<> section.
The default scope is `singleton`, but you can override this with the `@Scope` annotation,
as the following example shows:
@@ -6792,14 +6791,15 @@ as the following example shows:
===== `@Scope` and `scoped-proxy`
Spring offers a convenient way of working with scoped dependencies through
-<>. The easiest way to create such
-a proxy when using the XML configuration is the ` ` element.
-Configuring your beans in Java with a `@Scope` annotation offers equivalent support with
-the `proxyMode` attribute. The default is no proxy (`ScopedProxyMode.NO`), but you can
-specify `ScopedProxyMode.TARGET_CLASS` or `ScopedProxyMode.INTERFACES`.
+<>. The easiest way to create
+such a proxy when using the XML configuration is the ` ` element.
+Configuring your beans in Java with a `@Scope` annotation offers equivalent support
+with the `proxyMode` attribute. The default is no proxy (`ScopedProxyMode.NO`),
+but you can specify `ScopedProxyMode.TARGET_CLASS` or `ScopedProxyMode.INTERFACES`.
If you port the scoped proxy example from the XML reference documentation (see
-<>) to our `@Bean` using Java, it resembles the following:
+<>) to our `@Bean` using Java,
+it resembles the following:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -6935,7 +6935,7 @@ by using plain `@Component` classes.
[[beans-java-method-injection]]
==== Lookup Method Injection
-As noted earlier, <> is an
+As noted earlier, <> is an
advanced feature that you should use rarely. It is useful in cases where a
singleton-scoped bean has a dependency on a prototype-scoped bean. Using Java for this
type of configuration provides a natural means for implementing this pattern. The
@@ -7123,7 +7123,7 @@ issue, because no compiler is involved, and you can declare
When using `@Configuration` classes, the Java compiler places constraints on
the configuration model, in that references to other beans must be valid Java syntax.
-Fortunately, solving this problem is simple. As <>,
+Fortunately, solving this problem is simple. As <>,
a `@Bean` method can have an arbitrary number of parameters that describe the bean
dependencies. Consider the following more real-world scenario with several `@Configuration`
classes, each depending on beans declared in the others:
@@ -7581,8 +7581,8 @@ jdbc.password=
The {api-spring-framework}/core/env/Environment.html[`Environment`] interface
is an abstraction integrated in the container that models two key
-aspects of the application environment: <>
-and <>.
+aspects of the application environment: <>
+and <>.
A profile is a named, logical group of bean definitions to be registered with the
container only if the given profile is active. Beans may be assigned to a profile
@@ -7719,7 +7719,7 @@ NOTE: You cannot mix the `&` and `|` operators without using parentheses. For ex
`production & us-east | eu-central` is not a valid expression. It must be expressed as
`production & (us-east | eu-central)`.
-You can use `@Profile` as a <> for the purpose
+You can use `@Profile` as a <> for the purpose
of creating a custom composed annotation. The following example defines a custom
`@Production` annotation that you can use as a drop-in replacement for
`@Profile("production")`:
@@ -7915,9 +7915,9 @@ In addition, you can also declaratively activate profiles through the
`spring.profiles.active` property, which may be specified through system environment
variables, JVM system properties, servlet context parameters in `web.xml`, or even as an
entry in JNDI (see <>). In integration tests, active
-profiles can be declared by using the `@ActiveProfiles` annotation in the `spring-test` module
-(see <>).
+profiles can be declared by using the `@ActiveProfiles` annotation in the `spring-test`
+module (see <>).
Note that profiles are not an "`either-or`" proposition. You can activate multiple
profiles at once. Programmatically, you can provide multiple profile names to the
@@ -8169,9 +8169,10 @@ Alternatively, for XML configuration, you can use the `context:load-time-weaver`
Once configured for the `ApplicationContext`, any bean within that `ApplicationContext`
may implement `LoadTimeWeaverAware`, thereby receiving a reference to the load-time
weaver instance. This is particularly useful in combination with
-<> where load-time weaving may be necessary
-for JPA class transformation.
-Consult the {api-spring-framework}/orm/jpa/LocalContainerEntityManagerFactoryBean.html[`LocalContainerEntityManagerFactoryBean`]
+<> where load-time weaving may be
+necessary for JPA class transformation.
+Consult the
+{api-spring-framework}/orm/jpa/LocalContainerEntityManagerFactoryBean.html[`LocalContainerEntityManagerFactoryBean`]
javadoc for more detail. For more on AspectJ load-time weaving, see <>.
@@ -8180,7 +8181,7 @@ javadoc for more detail. For more on AspectJ load-time weaving, see <>, the `org.springframework.beans.factory`
+As discussed in the <>, the `org.springframework.beans.factory`
package provides basic functionality for managing and manipulating beans, including in a
programmatic way. The `org.springframework.context` package adds the
{api-spring-framework}/context/ApplicationContext.html[`ApplicationContext`]
@@ -8416,7 +8417,7 @@ class and the `ApplicationListener` interface. If a bean that implements the
Essentially, this is the standard Observer design pattern.
TIP: As of Spring 4.2, the event infrastructure has been significantly improved and offers
-an <> as well as the
+an <> as well as the
ability to publish any arbitrary event (that is, an object that does not necessarily
extend from `ApplicationEvent`). When such an object is published, we wrap it in an
event for you.
@@ -8640,12 +8641,12 @@ following example shows how to do so:
}
----
-It is also possible to add additional runtime filtering by using the `condition` attribute of the
-annotation that defines a <> , which should match to actually
-invoke the method for a particular event.
+It is also possible to add additional runtime filtering by using the `condition` attribute
+of the annotation that defines a <> , which should match
+to actually invoke the method for a particular event.
-The following example shows how our notifier can be rewritten to be invoked only if the `content` attribute
-of the event is equal to `my-event`:
+The following example shows how our notifier can be rewritten to be invoked only if the
+`content` attribute of the event is equal to `my-event`:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -8699,8 +8700,8 @@ method signature to return the event that should be published, as the following
}
----
-NOTE: This feature is not supported for <>.
+NOTE: This feature is not supported for
+<>.
This new method publishes a new `ListUpdateEvent` for every `BlackListEvent` handled by the
method above. If you need to publish several events, you can return a `Collection` of events
@@ -8711,8 +8712,8 @@ instead.
==== Asynchronous Listeners
If you want a particular listener to process events asynchronously, you can reuse the
-<>. The
-following example shows how to do so:
+<>.
+The following example shows how to do so:
[source,java,indent=0]
[subs="verbatim,quotes"]
@@ -8801,9 +8802,8 @@ an event.
[[context-functionality-resources]]
=== Convenient Access to Low-level Resources
-For optimal usage and understanding of application contexts, you should
-familiarize yourself with Spring's `Resource` abstraction, as described in
-<>.
+For optimal usage and understanding of application contexts, you should familiarize
+yourself with Spring's `Resource` abstraction, as described in <>.
An application context is a `ResourceLoader`, which can be used to load `Resource` objects.
A `Resource` is essentially a more feature rich version of the JDK `java.net.URL` class.
@@ -8957,11 +8957,11 @@ by convention (that is, by bean name or by bean type -- in particular, post-proc
while a plain `DefaultListableBeanFactory` is agnostic about any special beans.
For many extended container features, such as annotation processing and AOP proxying,
-the <> is essential.
+the <> is essential.
If you use only a plain `DefaultListableBeanFactory`, such post-processors do not
get detected and activated by default. This situation could be confusing, because
-nothing is actually wrong with your bean configuration. Rather, in such a scenario, the
-container needs to be fully bootstrapped through additional setup.
+nothing is actually wrong with your bean configuration. Rather, in such a scenario,
+the container needs to be fully bootstrapped through additional setup.
The following table lists features provided by the `BeanFactory` and
`ApplicationContext` interfaces and implementations.
diff --git a/src/docs/asciidoc/core/core-databuffer-codec.adoc b/src/docs/asciidoc/core/core-databuffer-codec.adoc
index 2669c844eda..50f00110c0c 100644
--- a/src/docs/asciidoc/core/core-databuffer-codec.adoc
+++ b/src/docs/asciidoc/core/core-databuffer-codec.adoc
@@ -10,7 +10,7 @@ APIs as follows:
* <> abstracts the creation of a data buffer.
* <> represents a byte buffer, which may be
-<>.
+<>.
* <> offers utility methods for data buffers.
* <> decode or encode streams data buffer streams into higher level objects.
@@ -93,7 +93,6 @@ composite buffers, if that's supported by the underlying byte buffer API.
-
[[codecs]]
== Codecs
@@ -105,7 +104,7 @@ The `org.springframework.core.codec` package provides the following strategy int
The `spring-core` module provides `byte[]`, `ByteBuffer`, `DataBuffer`, `Resource`, and
`String` encoder and decoder implementations. The `spring-web` module adds Jackson JSON,
Jackson Smile, JAXB2, Protocol Buffers and other encoders and decoders. See
-<> in the WebFlux section.
+<> in the WebFlux section.
@@ -114,7 +113,7 @@ Jackson Smile, JAXB2, Protocol Buffers and other encoders and decoders. See
== Using `DataBuffer`
When working with data buffers, special care must be taken to ensure buffers are released
-since they may be <>. We'll use codecs to illustrate
+since they may be <>. We'll use codecs to illustrate
how that works but the concepts apply more generally. Let's see what codecs must do
internally to manage data buffers.
diff --git a/src/docs/asciidoc/core/core-expressions.adoc b/src/docs/asciidoc/core/core-expressions.adoc
index ba8f238ad03..14adf2ee5ff 100644
--- a/src/docs/asciidoc/core/core-expressions.adoc
+++ b/src/docs/asciidoc/core/core-expressions.adoc
@@ -10,8 +10,8 @@ While there are several other Java expression languages available -- OGNL, MVEL,
EL, to name a few -- the Spring Expression Language was created to provide the Spring
community with a single well supported expression language that can be used across all
the products in the Spring portfolio. Its language features are driven by the
-requirements of the projects in the Spring portfolio, including tooling requirements for
-code completion support within the Eclipse-based Spring Tool Suite. That said,
+requirements of the projects in the Spring portfolio, including tooling requirements
+for code completion support within the Eclipse-based Spring Tool Suite. That said,
SpEL is based on a technology-agnostic API that lets other expression language
implementations be integrated, should the need arise.
@@ -20,14 +20,14 @@ portfolio, it is not directly tied to Spring and can be used independently. To
be self contained, many of the examples in this chapter use SpEL as if it were an
independent expression language. This requires creating a few bootstrapping
infrastructure classes, such as the parser. Most Spring users need not deal with
-this infrastructure and can, instead, author only expression strings for evaluation. An
-example of this typical use is the integration of SpEL into creating XML or annotation-based
-bean definitions, as shown in <>.
+this infrastructure and can, instead, author only expression strings for evaluation.
+An example of this typical use is the integration of SpEL into creating XML or
+annotation-based bean definitions, as shown in
+<>.
This chapter covers the features of the expression language, its API, and its language
-syntax. In several places, `Inventor` and `Society` classes are used as the
-target objects for expression evaluation. These class declarations and the data used to
+syntax. In several places, `Inventor` and `Society` classes are used as the target
+objects for expression evaluation. These class declarations and the data used to
populate them are listed at the end of the chapter.
The expression language supports the following functionality:
@@ -60,7 +60,7 @@ The expression language supports the following functionality:
This section introduces the simple use of SpEL interfaces and its expression language.
The complete language reference can be found in
-<>.
+<>.
The following code introduces the SpEL API to evaluate the literal string expression,
`Hello World`.
@@ -319,13 +319,14 @@ interpreter and only 3ms using the compiled version of the expression.
[[expressions-compiler-configuration]]
==== Compiler Configuration
-The compiler is not turned on by default, but you can turn it on in either of two different ways.
-You can turn it on by using the parser configuration process (<>)
-or by using a system property when SpEL usage is embedded inside another component. This section
+The compiler is not turned on by default, but you can turn it on in either of two
+different ways. You can turn it on by using the parser configuration process
+(<>) or by using a system
+property when SpEL usage is embedded inside another component. This section
discusses both of these options.
-The compiler can operate in one of three modes, which are captured
-in the `org.springframework.expression.spel.SpelCompilerMode` enum. The modes are as follows:
+The compiler can operate in one of three modes, which are captured in the
+`org.springframework.expression.spel.SpelCompilerMode` enum. The modes are as follows:
* `OFF` (default): The compiler is switched off.
* `IMMEDIATE`: In immediate mode, the expressions are compiled as soon as possible. This
@@ -612,7 +613,7 @@ By default, real numbers are parsed by using Double.parseDouble().
Navigating with property references is easy. To do so, use a period to indicate a nested
property value. The instances of the `Inventor` class, `pupin` and `tesla`, were populated with
-data listed in the <> section.
+data listed in the <> section.
To navigate "`down`" and get Tesla's year of birth and Pupin's city of birth, we use the following
expressions:
diff --git a/src/docs/asciidoc/core/core-null-safety.adoc b/src/docs/asciidoc/core/core-null-safety.adoc
index 95b7ed82be3..07044b68503 100644
--- a/src/docs/asciidoc/core/core-null-safety.adoc
+++ b/src/docs/asciidoc/core/core-null-safety.adoc
@@ -1,29 +1,31 @@
-[[null-safety]]
+[-[null-safety]]
= Null-safety
-Although Java does not let you express null-safety with its type system, Spring Framework
-now provides the following annotations in the `org.springframework.lang` package to let you declare
-nullability of APIs and fields:
+Although Java does not let you express null-safety with its type system, the Spring Framework
+now provides the following annotations in the `org.springframework.lang` package to let you
+declare nullability of APIs and fields:
-* {api-spring-framework}/lang/NonNull.html[`@NonNull`]: Annotation to indicate that a specific parameter,
-return value, or field cannot be `null` (not needed on parameter and return value
-where `@NonNullApi` and `@NonNullFields` apply) .
-* {api-spring-framework}/lang/Nullable.html[`@Nullable`]: Annotation to indicate that a specific
-parameter, return value, or field can be `null`.
+* {api-spring-framework}/lang/Nullable.html[`@Nullable`]: Annotation to indicate that a
+specific parameter, return value, or field can be `null`.
+* {api-spring-framework}/lang/NonNull.html[`@NonNull`]: Annotation to indicate that a specific
+parameter, return value, or field cannot be `null` (not needed on parameters / return values
+and fields where `@NonNullApi` and `@NonNullFields` apply, respectively).
* {api-spring-framework}/lang/NonNullApi.html[`@NonNullApi`]: Annotation at the package level
-that declares non-null as the default behavior for parameters and return values.
+that declares non-null as the default semantics for parameters and return values.
* {api-spring-framework}/lang/NonNullFields.html[`@NonNullFields`]: Annotation at the package
-level that declares non-null as the default behavior for fields.
+level that declares non-null as the default semantics for fields.
-Spring Framework leverages itself these annotations, but they can also be used in any Spring based
-Java project to declare null-safe APIs and optionally null-safe fields. Generic type arguments,
-varargs and array elements nullability are not supported yet, but should be in an upcoming
-release, see https://jira.spring.io/browse/SPR-15942[SPR-15942] for up-to-date information.
-Nullability declaration are expected to be fine-tuned between Spring Framework release,
-including minor ones. Nullability of types used inside method bodies is outside of the
-scope of this feature.
+The Spring Framework itself leverages these annotations, but they can also be used in any
+Spring-based Java project to declare null-safe APIs and optionally null-safe fields.
+Generic type arguments, varargs and array elements nullability are not supported yet but
+should be in an upcoming release, see https://jira.spring.io/browse/SPR-15942[SPR-15942]
+for up-to-date information. Nullability declarations are expected to be fine-tuned between
+Spring Framework releases, including minor ones. Nullability of types used inside method
+bodies is outside of the scope of this feature.
-NOTE: Libraries like Reactor or Spring Data provide null-safe APIs that use this feature.
+NOTE: Other common libraries such as Reactor and Spring Data provide null-safe APIs that
+use a similar nullability arrangement, delivering a consistent overall experience for
+Spring application developers.
@@ -32,25 +34,23 @@ NOTE: Libraries like Reactor or Spring Data provide null-safe APIs that use this
In addition to providing an explicit declaration for Spring Framework API nullability,
these annotations can be used by an IDE (such as IDEA or Eclipse) to provide useful
-warnings related to null-safety in order to avoid `NullPointerException`
-at runtime.
+warnings related to null-safety in order to avoid `NullPointerException` at runtime.
They are also used to make Spring API null-safe in Kotlin projects, since Kotlin natively
supports https://kotlinlang.org/docs/reference/null-safety.html[null-safety]. More details
-are available in the <