Skip to content

Commit b598ad3

Browse files
committed
Polishing
1 parent b44ef70 commit b598ad3

File tree

5 files changed

+58
-46
lines changed

5 files changed

+58
-46
lines changed

spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,6 @@
135135
public abstract class AbstractApplicationContext extends DefaultResourceLoader
136136
implements ConfigurableApplicationContext {
137137

138-
/**
139-
* The name of the {@link LifecycleProcessor} bean in the context.
140-
* If none is supplied, a {@link DefaultLifecycleProcessor} is used.
141-
* @since 3.0
142-
* @see org.springframework.context.LifecycleProcessor
143-
* @see org.springframework.context.support.DefaultLifecycleProcessor
144-
* @see #start()
145-
* @see #stop()
146-
*/
147-
public static final String LIFECYCLE_PROCESSOR_BEAN_NAME = "lifecycleProcessor";
148-
149138
/**
150139
* The name of the {@link MessageSource} bean in the context.
151140
* If none is supplied, message resolution is delegated to the parent.
@@ -166,6 +155,17 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
166155
*/
167156
public static final String APPLICATION_EVENT_MULTICASTER_BEAN_NAME = "applicationEventMulticaster";
168157

158+
/**
159+
* The name of the {@link LifecycleProcessor} bean in the context.
160+
* If none is supplied, a {@link DefaultLifecycleProcessor} is used.
161+
* @since 3.0
162+
* @see org.springframework.context.LifecycleProcessor
163+
* @see org.springframework.context.support.DefaultLifecycleProcessor
164+
* @see #start()
165+
* @see #stop()
166+
*/
167+
public static final String LIFECYCLE_PROCESSOR_BEAN_NAME = "lifecycleProcessor";
168+
169169

170170
static {
171171
// Eagerly load the ContextClosedEvent class to avoid weird classloader issues
@@ -796,8 +796,9 @@ protected void registerBeanPostProcessors(ConfigurableListableBeanFactory beanFa
796796
}
797797

798798
/**
799-
* Initialize the MessageSource.
800-
* Use parent's if none defined in this context.
799+
* Initialize the {@link MessageSource}.
800+
* <p>Uses parent's {@code MessageSource} if none defined in this context.
801+
* @see #MESSAGE_SOURCE_BEAN_NAME
801802
*/
802803
protected void initMessageSource() {
803804
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
@@ -827,8 +828,9 @@ protected void initMessageSource() {
827828
}
828829

829830
/**
830-
* Initialize the ApplicationEventMulticaster.
831-
* Uses SimpleApplicationEventMulticaster if none defined in the context.
831+
* Initialize the {@link ApplicationEventMulticaster}.
832+
* <p>Uses {@link SimpleApplicationEventMulticaster} if none defined in the context.
833+
* @see #APPLICATION_EVENT_MULTICASTER_BEAN_NAME
832834
* @see org.springframework.context.event.SimpleApplicationEventMulticaster
833835
*/
834836
protected void initApplicationEventMulticaster() {
@@ -851,15 +853,16 @@ protected void initApplicationEventMulticaster() {
851853
}
852854

853855
/**
854-
* Initialize the LifecycleProcessor.
855-
* Uses DefaultLifecycleProcessor if none defined in the context.
856+
* Initialize the {@link LifecycleProcessor}.
857+
* <p>Uses {@link DefaultLifecycleProcessor} if none defined in the context.
858+
* @since 3.0
859+
* @see #LIFECYCLE_PROCESSOR_BEAN_NAME
856860
* @see org.springframework.context.support.DefaultLifecycleProcessor
857861
*/
858862
protected void initLifecycleProcessor() {
859863
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
860864
if (beanFactory.containsLocalBean(LIFECYCLE_PROCESSOR_BEAN_NAME)) {
861-
this.lifecycleProcessor =
862-
beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
865+
this.lifecycleProcessor = beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
863866
if (logger.isTraceEnabled()) {
864867
logger.trace("Using LifecycleProcessor [" + this.lifecycleProcessor + "]");
865868
}

spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -264,8 +264,9 @@ public void setValidationMode(ValidationMode validationMode) {
264264
* @see jakarta.persistence.spi.PersistenceUnitInfo#getNonJtaDataSource()
265265
* @see #setPersistenceUnitManager
266266
*/
267-
public void setDataSource(DataSource dataSource) {
268-
this.internalPersistenceUnitManager.setDataSourceLookup(new SingleDataSourceLookup(dataSource));
267+
public void setDataSource(@Nullable DataSource dataSource) {
268+
this.internalPersistenceUnitManager.setDataSourceLookup(
269+
dataSource != null ? new SingleDataSourceLookup(dataSource) : null);
269270
this.internalPersistenceUnitManager.setDefaultDataSource(dataSource);
270271
}
271272

@@ -281,8 +282,9 @@ public void setDataSource(DataSource dataSource) {
281282
* @see jakarta.persistence.spi.PersistenceUnitInfo#getJtaDataSource()
282283
* @see #setPersistenceUnitManager
283284
*/
284-
public void setJtaDataSource(DataSource jtaDataSource) {
285-
this.internalPersistenceUnitManager.setDataSourceLookup(new SingleDataSourceLookup(jtaDataSource));
285+
public void setJtaDataSource(@Nullable DataSource jtaDataSource) {
286+
this.internalPersistenceUnitManager.setDataSourceLookup(
287+
jtaDataSource != null ? new SingleDataSourceLookup(jtaDataSource) : null);
286288
this.internalPersistenceUnitManager.setDefaultJtaDataSource(jtaDataSource);
287289
}
288290

@@ -427,6 +429,7 @@ public String getPersistenceUnitName() {
427429
}
428430

429431
@Override
432+
@Nullable
430433
public DataSource getDataSource() {
431434
if (this.persistenceUnitInfo != null) {
432435
return (this.persistenceUnitInfo.getJtaDataSource() != null ?

spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,28 +28,18 @@
2828
* shared JPA EntityManagerFactory in a Spring application context; the
2929
* EntityManagerFactory can then be passed to JPA-based DAOs via
3030
* dependency injection. Note that switching to a JNDI lookup or to a
31-
* {@link LocalContainerEntityManagerFactoryBean}
32-
* definition is just a matter of configuration!
31+
* {@link LocalContainerEntityManagerFactoryBean} definition based on the
32+
* JPA container contract is just a matter of configuration!
3333
*
3434
* <p>Configuration settings are usually read from a {@code META-INF/persistence.xml}
3535
* config file, residing in the class path, according to the JPA standalone bootstrap
36-
* contract. Additionally, most JPA providers will require a special VM agent
37-
* (specified on JVM startup) that allows them to instrument application classes.
38-
* See the Java Persistence API specification and your provider documentation
39-
* for setup details.
40-
*
41-
* <p>This EntityManagerFactory bootstrap is appropriate for standalone applications
42-
* which solely use JPA for data access. If you want to set up your persistence
43-
* provider for an external DataSource and/or for global transactions which span
44-
* multiple resources, you will need to either deploy it into a full Jakarta EE
45-
* application server and access the deployed EntityManagerFactory via JNDI,
46-
* or use Spring's {@link LocalContainerEntityManagerFactoryBean} with appropriate
47-
* configuration for local setup according to JPA's container contract.
36+
* contract. See the Java Persistence API specification and your persistence provider
37+
* documentation for setup details. Additionally, JPA properties can also be added
38+
* on this FactoryBean via {@link #setJpaProperties}/{@link #setJpaPropertyMap}.
4839
*
4940
* <p><b>Note:</b> This FactoryBean has limited configuration power in terms of
50-
* what configuration it is able to pass to the JPA provider. If you need more
51-
* flexible configuration, for example passing a Spring-managed JDBC DataSource
52-
* to the JPA provider, consider using Spring's more powerful
41+
* the configuration that it is able to pass to the JPA provider. If you need
42+
* more flexible configuration options, consider using Spring's more powerful
5343
* {@link LocalContainerEntityManagerFactoryBean} instead.
5444
*
5545
* @author Juergen Hoeller

spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -292,6 +292,11 @@ public void setContentLength(int contentLength) {
292292
doAddHeaderValue(HttpHeaders.CONTENT_LENGTH, contentLength, true);
293293
}
294294

295+
/**
296+
* Get the length of the content body from the HTTP Content-Length header.
297+
* @return the value of the Content-Length header
298+
* @see #setContentLength(int)
299+
*/
295300
public int getContentLength() {
296301
return (int) this.contentLength;
297302
}
@@ -742,7 +747,7 @@ private void setCookie(Cookie cookie) {
742747

743748
@Override
744749
public void setStatus(int status) {
745-
if (!this.isCommitted()) {
750+
if (!isCommitted()) {
746751
this.status = status;
747752
}
748753
}
@@ -752,6 +757,9 @@ public int getStatus() {
752757
return this.status;
753758
}
754759

760+
/**
761+
* Return the error message used when calling {@link HttpServletResponse#sendError(int, String)}.
762+
*/
755763
@Nullable
756764
public String getErrorMessage() {
757765
return this.errorMessage;

spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -292,6 +292,11 @@ public void setContentLength(int contentLength) {
292292
doAddHeaderValue(HttpHeaders.CONTENT_LENGTH, contentLength, true);
293293
}
294294

295+
/**
296+
* Get the length of the content body from the HTTP Content-Length header.
297+
* @return the value of the Content-Length header
298+
* @see #setContentLength(int)
299+
*/
295300
public int getContentLength() {
296301
return (int) this.contentLength;
297302
}
@@ -742,7 +747,7 @@ private void setCookie(Cookie cookie) {
742747

743748
@Override
744749
public void setStatus(int status) {
745-
if (!this.isCommitted()) {
750+
if (!isCommitted()) {
746751
this.status = status;
747752
}
748753
}
@@ -752,6 +757,9 @@ public int getStatus() {
752757
return this.status;
753758
}
754759

760+
/**
761+
* Return the error message used when calling {@link HttpServletResponse#sendError(int, String)}.
762+
*/
755763
@Nullable
756764
public String getErrorMessage() {
757765
return this.errorMessage;

0 commit comments

Comments
 (0)