Polishing
This commit is contained in:
parent
6d9736acd0
commit
f22a1eece4
|
|
@ -53,8 +53,6 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
*/
|
*/
|
||||||
class AspectJExpressionPointcutTests {
|
class AspectJExpressionPointcutTests {
|
||||||
|
|
||||||
public static final String MATCH_ALL_METHODS = "execution(* *(..))";
|
|
||||||
|
|
||||||
private Method getAge;
|
private Method getAge;
|
||||||
|
|
||||||
private Method setAge;
|
private Method setAge;
|
||||||
|
|
@ -175,24 +173,24 @@ class AspectJExpressionPointcutTests {
|
||||||
@Test
|
@Test
|
||||||
void testFriendlyErrorOnNoLocationClassMatching() {
|
void testFriendlyErrorOnNoLocationClassMatching() {
|
||||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException()
|
||||||
pc.matches(ITestBean.class))
|
.isThrownBy(() -> pc.matches(ITestBean.class))
|
||||||
.withMessageContaining("expression");
|
.withMessageContaining("expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFriendlyErrorOnNoLocation2ArgMatching() {
|
void testFriendlyErrorOnNoLocation2ArgMatching() {
|
||||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException()
|
||||||
pc.matches(getAge, ITestBean.class))
|
.isThrownBy(() -> pc.matches(getAge, ITestBean.class))
|
||||||
.withMessageContaining("expression");
|
.withMessageContaining("expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFriendlyErrorOnNoLocation3ArgMatching() {
|
void testFriendlyErrorOnNoLocation3ArgMatching() {
|
||||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException()
|
||||||
pc.matches(getAge, ITestBean.class, (Object[]) null))
|
.isThrownBy(() -> pc.matches(getAge, ITestBean.class, (Object[]) null))
|
||||||
.withMessageContaining("expression");
|
.withMessageContaining("expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,8 +208,10 @@ class AspectJExpressionPointcutTests {
|
||||||
// not currently testable in a reliable fashion
|
// not currently testable in a reliable fashion
|
||||||
//assertDoesNotMatchStringClass(classFilter);
|
//assertDoesNotMatchStringClass(classFilter);
|
||||||
|
|
||||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 12D)).as("Should match with setSomeNumber with Double input").isTrue();
|
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 12D))
|
||||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 11)).as("Should not match setSomeNumber with Integer input").isFalse();
|
.as("Should match with setSomeNumber with Double input").isTrue();
|
||||||
|
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 11))
|
||||||
|
.as("Should not match setSomeNumber with Integer input").isFalse();
|
||||||
assertThat(methodMatcher.matches(getAge, TestBean.class)).as("Should not match getAge").isFalse();
|
assertThat(methodMatcher.matches(getAge, TestBean.class)).as("Should not match getAge").isFalse();
|
||||||
assertThat(methodMatcher.isRuntime()).as("Should be a runtime match").isTrue();
|
assertThat(methodMatcher.isRuntime()).as("Should be a runtime match").isTrue();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,17 +137,6 @@ import org.springframework.util.ReflectionUtils;
|
||||||
public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
implements ConfigurableApplicationContext {
|
implements ConfigurableApplicationContext {
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the {@link LifecycleProcessor} bean in the context.
|
|
||||||
* If none is supplied, a {@link DefaultLifecycleProcessor} is used.
|
|
||||||
* @since 3.0
|
|
||||||
* @see org.springframework.context.LifecycleProcessor
|
|
||||||
* @see org.springframework.context.support.DefaultLifecycleProcessor
|
|
||||||
* @see #start()
|
|
||||||
* @see #stop()
|
|
||||||
*/
|
|
||||||
public static final String LIFECYCLE_PROCESSOR_BEAN_NAME = "lifecycleProcessor";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the {@link MessageSource} bean in the context.
|
* The name of the {@link MessageSource} bean in the context.
|
||||||
* If none is supplied, message resolution is delegated to the parent.
|
* If none is supplied, message resolution is delegated to the parent.
|
||||||
|
|
@ -168,6 +157,17 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
*/
|
*/
|
||||||
public static final String APPLICATION_EVENT_MULTICASTER_BEAN_NAME = "applicationEventMulticaster";
|
public static final String APPLICATION_EVENT_MULTICASTER_BEAN_NAME = "applicationEventMulticaster";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the {@link LifecycleProcessor} bean in the context.
|
||||||
|
* If none is supplied, a {@link DefaultLifecycleProcessor} is used.
|
||||||
|
* @since 3.0
|
||||||
|
* @see org.springframework.context.LifecycleProcessor
|
||||||
|
* @see org.springframework.context.support.DefaultLifecycleProcessor
|
||||||
|
* @see #start()
|
||||||
|
* @see #stop()
|
||||||
|
*/
|
||||||
|
public static final String LIFECYCLE_PROCESSOR_BEAN_NAME = "lifecycleProcessor";
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Eagerly load the ContextClosedEvent class to avoid weird classloader issues
|
// Eagerly load the ContextClosedEvent class to avoid weird classloader issues
|
||||||
|
|
@ -806,8 +806,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the MessageSource.
|
* Initialize the {@link MessageSource}.
|
||||||
* Use parent's if none defined in this context.
|
* <p>Uses parent's {@code MessageSource} if none defined in this context.
|
||||||
|
* @see #MESSAGE_SOURCE_BEAN_NAME
|
||||||
*/
|
*/
|
||||||
protected void initMessageSource() {
|
protected void initMessageSource() {
|
||||||
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
|
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
|
||||||
|
|
@ -837,8 +838,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the ApplicationEventMulticaster.
|
* Initialize the {@link ApplicationEventMulticaster}.
|
||||||
* Uses SimpleApplicationEventMulticaster if none defined in the context.
|
* <p>Uses {@link SimpleApplicationEventMulticaster} if none defined in the context.
|
||||||
|
* @see #APPLICATION_EVENT_MULTICASTER_BEAN_NAME
|
||||||
* @see org.springframework.context.event.SimpleApplicationEventMulticaster
|
* @see org.springframework.context.event.SimpleApplicationEventMulticaster
|
||||||
*/
|
*/
|
||||||
protected void initApplicationEventMulticaster() {
|
protected void initApplicationEventMulticaster() {
|
||||||
|
|
@ -861,15 +863,16 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the LifecycleProcessor.
|
* Initialize the {@link LifecycleProcessor}.
|
||||||
* Uses DefaultLifecycleProcessor if none defined in the context.
|
* <p>Uses {@link DefaultLifecycleProcessor} if none defined in the context.
|
||||||
|
* @since 3.0
|
||||||
|
* @see #LIFECYCLE_PROCESSOR_BEAN_NAME
|
||||||
* @see org.springframework.context.support.DefaultLifecycleProcessor
|
* @see org.springframework.context.support.DefaultLifecycleProcessor
|
||||||
*/
|
*/
|
||||||
protected void initLifecycleProcessor() {
|
protected void initLifecycleProcessor() {
|
||||||
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
|
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
|
||||||
if (beanFactory.containsLocalBean(LIFECYCLE_PROCESSOR_BEAN_NAME)) {
|
if (beanFactory.containsLocalBean(LIFECYCLE_PROCESSOR_BEAN_NAME)) {
|
||||||
this.lifecycleProcessor =
|
this.lifecycleProcessor = beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
|
||||||
beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
|
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("Using LifecycleProcessor [" + this.lifecycleProcessor + "]");
|
logger.trace("Using LifecycleProcessor [" + this.lifecycleProcessor + "]");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -276,8 +276,9 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
|
||||||
* @see jakarta.persistence.spi.PersistenceUnitInfo#getNonJtaDataSource()
|
* @see jakarta.persistence.spi.PersistenceUnitInfo#getNonJtaDataSource()
|
||||||
* @see #setPersistenceUnitManager
|
* @see #setPersistenceUnitManager
|
||||||
*/
|
*/
|
||||||
public void setDataSource(DataSource dataSource) {
|
public void setDataSource(@Nullable DataSource dataSource) {
|
||||||
this.internalPersistenceUnitManager.setDataSourceLookup(new SingleDataSourceLookup(dataSource));
|
this.internalPersistenceUnitManager.setDataSourceLookup(
|
||||||
|
dataSource != null ? new SingleDataSourceLookup(dataSource) : null);
|
||||||
this.internalPersistenceUnitManager.setDefaultDataSource(dataSource);
|
this.internalPersistenceUnitManager.setDefaultDataSource(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -293,8 +294,9 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
|
||||||
* @see jakarta.persistence.spi.PersistenceUnitInfo#getJtaDataSource()
|
* @see jakarta.persistence.spi.PersistenceUnitInfo#getJtaDataSource()
|
||||||
* @see #setPersistenceUnitManager
|
* @see #setPersistenceUnitManager
|
||||||
*/
|
*/
|
||||||
public void setJtaDataSource(DataSource jtaDataSource) {
|
public void setJtaDataSource(@Nullable DataSource jtaDataSource) {
|
||||||
this.internalPersistenceUnitManager.setDataSourceLookup(new SingleDataSourceLookup(jtaDataSource));
|
this.internalPersistenceUnitManager.setDataSourceLookup(
|
||||||
|
jtaDataSource != null ? new SingleDataSourceLookup(jtaDataSource) : null);
|
||||||
this.internalPersistenceUnitManager.setDefaultJtaDataSource(jtaDataSource);
|
this.internalPersistenceUnitManager.setDefaultJtaDataSource(jtaDataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -439,6 +441,7 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public DataSource getDataSource() {
|
public DataSource getDataSource() {
|
||||||
if (this.persistenceUnitInfo != null) {
|
if (this.persistenceUnitInfo != null) {
|
||||||
return (this.persistenceUnitInfo.getJtaDataSource() != null ?
|
return (this.persistenceUnitInfo.getJtaDataSource() != null ?
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -28,28 +28,18 @@ import jakarta.persistence.spi.PersistenceProvider;
|
||||||
* shared JPA EntityManagerFactory in a Spring application context; the
|
* shared JPA EntityManagerFactory in a Spring application context; the
|
||||||
* EntityManagerFactory can then be passed to JPA-based DAOs via
|
* EntityManagerFactory can then be passed to JPA-based DAOs via
|
||||||
* dependency injection. Note that switching to a JNDI lookup or to a
|
* dependency injection. Note that switching to a JNDI lookup or to a
|
||||||
* {@link LocalContainerEntityManagerFactoryBean}
|
* {@link LocalContainerEntityManagerFactoryBean} definition based on the
|
||||||
* definition is just a matter of configuration!
|
* JPA container contract is just a matter of configuration!
|
||||||
*
|
*
|
||||||
* <p>Configuration settings are usually read from a {@code META-INF/persistence.xml}
|
* <p>Configuration settings are usually read from a {@code META-INF/persistence.xml}
|
||||||
* config file, residing in the class path, according to the JPA standalone bootstrap
|
* config file, residing in the class path, according to the JPA standalone bootstrap
|
||||||
* contract. Additionally, most JPA providers will require a special VM agent
|
* contract. See the Java Persistence API specification and your persistence provider
|
||||||
* (specified on JVM startup) that allows them to instrument application classes.
|
* documentation for setup details. Additionally, JPA properties can also be added
|
||||||
* See the Java Persistence API specification and your provider documentation
|
* on this FactoryBean via {@link #setJpaProperties}/{@link #setJpaPropertyMap}.
|
||||||
* for setup details.
|
|
||||||
*
|
|
||||||
* <p>This EntityManagerFactory bootstrap is appropriate for standalone applications
|
|
||||||
* which solely use JPA for data access. If you want to set up your persistence
|
|
||||||
* provider for an external DataSource and/or for global transactions which span
|
|
||||||
* multiple resources, you will need to either deploy it into a full Jakarta EE
|
|
||||||
* application server and access the deployed EntityManagerFactory via JNDI,
|
|
||||||
* or use Spring's {@link LocalContainerEntityManagerFactoryBean} with appropriate
|
|
||||||
* configuration for local setup according to JPA's container contract.
|
|
||||||
*
|
*
|
||||||
* <p><b>Note:</b> This FactoryBean has limited configuration power in terms of
|
* <p><b>Note:</b> This FactoryBean has limited configuration power in terms of
|
||||||
* what configuration it is able to pass to the JPA provider. If you need more
|
* the configuration that it is able to pass to the JPA provider. If you need
|
||||||
* flexible configuration, for example passing a Spring-managed JDBC DataSource
|
* more flexible configuration options, consider using Spring's more powerful
|
||||||
* to the JPA provider, consider using Spring's more powerful
|
|
||||||
* {@link LocalContainerEntityManagerFactoryBean} instead.
|
* {@link LocalContainerEntityManagerFactoryBean} instead.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -775,7 +775,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStatus(int status) {
|
public void setStatus(int status) {
|
||||||
if (!this.isCommitted()) {
|
if (!isCommitted()) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -775,7 +775,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStatus(int status) {
|
public void setStatus(int status) {
|
||||||
if (!this.isCommitted()) {
|
if (!isCommitted()) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -785,6 +785,9 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
||||||
return this.status;
|
return this.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the error message used when calling {@link HttpServletResponse#sendError(int, String)}.
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getErrorMessage() {
|
public String getErrorMessage() {
|
||||||
return this.errorMessage;
|
return this.errorMessage;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue