Polishing
This commit is contained in:
@@ -135,17 +135,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.
|
||||||
@@ -166,6 +155,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
|
||||||
@@ -796,8 +796,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();
|
||||||
@@ -827,8 +828,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() {
|
||||||
@@ -851,15 +853,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 + "]");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -264,8 +264,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,8 +282,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,6 +429,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.
|
||||||
@@ -292,6 +292,11 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
|||||||
doAddHeaderValue(HttpHeaders.CONTENT_LENGTH, contentLength, true);
|
doAddHeaderValue(HttpHeaders.CONTENT_LENGTH, contentLength, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the length of the content body from the HTTP Content-Length header.
|
||||||
|
* @return the value of the Content-Length header
|
||||||
|
* @see #setContentLength(int)
|
||||||
|
*/
|
||||||
public int getContentLength() {
|
public int getContentLength() {
|
||||||
return (int) this.contentLength;
|
return (int) this.contentLength;
|
||||||
}
|
}
|
||||||
@@ -742,7 +747,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -752,6 +757,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;
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -292,6 +292,11 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
|||||||
doAddHeaderValue(HttpHeaders.CONTENT_LENGTH, contentLength, true);
|
doAddHeaderValue(HttpHeaders.CONTENT_LENGTH, contentLength, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the length of the content body from the HTTP Content-Length header.
|
||||||
|
* @return the value of the Content-Length header
|
||||||
|
* @see #setContentLength(int)
|
||||||
|
*/
|
||||||
public int getContentLength() {
|
public int getContentLength() {
|
||||||
return (int) this.contentLength;
|
return (int) this.contentLength;
|
||||||
}
|
}
|
||||||
@@ -742,7 +747,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -752,6 +757,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;
|
||||||
|
|||||||
Reference in New Issue
Block a user