DynamicRegistrationBean Class — spring-boot Architecture
Architecture documentation for the DynamicRegistrationBean class in DynamicRegistrationBean.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/main/java/org/springframework/boot/web/servlet/DynamicRegistrationBean.java lines 42–172
public abstract class DynamicRegistrationBean<D extends Registration.Dynamic> extends RegistrationBean
implements BeanNameAware {
private static final Log logger = LogFactory.getLog(RegistrationBean.class);
private @Nullable String name;
private boolean asyncSupported = true;
private Map<String, String> initParameters = new LinkedHashMap<>();
private @Nullable String beanName;
private boolean ignoreRegistrationFailure;
/**
* Set the name of this registration. If not specified the bean name will be used.
* @param name the name of the registration
*/
public void setName(String name) {
Assert.hasLength(name, "'name' must not be empty");
this.name = name;
}
/**
* Sets if asynchronous operations are supported for this registration. If not
* specified defaults to {@code true}.
* @param asyncSupported if async is supported
*/
public void setAsyncSupported(boolean asyncSupported) {
this.asyncSupported = asyncSupported;
}
/**
* Returns if asynchronous operations are supported for this registration.
* @return if async is supported
*/
public boolean isAsyncSupported() {
return this.asyncSupported;
}
/**
* Set init-parameters for this registration. Calling this method will replace any
* existing init-parameters.
* @param initParameters the init parameters
* @see #getInitParameters
* @see #addInitParameter
*/
public void setInitParameters(Map<String, String> initParameters) {
Assert.notNull(initParameters, "'initParameters' must not be null");
this.initParameters = new LinkedHashMap<>(initParameters);
}
/**
* Returns a mutable Map of the registration init-parameters.
* @return the init parameters
*/
public Map<String, String> getInitParameters() {
return this.initParameters;
}
/**
* Add a single init-parameter, replacing any existing parameter with the same name.
* @param name the init-parameter name
* @param value the init-parameter value
*/
public void addInitParameter(String name, String value) {
Assert.notNull(name, "'name' must not be null");
this.initParameters.put(name, value);
}
@Override
protected final void register(String description, ServletContext servletContext) {
D registration = addRegistration(description, servletContext);
if (registration == null) {
if (this.ignoreRegistrationFailure) {
logger.info(StringUtils.capitalize(description) + " was not registered (possibly already registered?)");
return;
}
throw new IllegalStateException(
"Failed to register '%s' on the servlet context. Possibly already registered?"
.formatted(description));
}
configure(registration);
}
/**
* Sets whether registration failures should be ignored. If set to true, a failure
* will be logged. If set to false, an {@link IllegalStateException} will be thrown.
* @param ignoreRegistrationFailure whether to ignore registration failures
* @since 3.1.0
*/
public void setIgnoreRegistrationFailure(boolean ignoreRegistrationFailure) {
this.ignoreRegistrationFailure = ignoreRegistrationFailure;
}
@Override
public void setBeanName(String name) {
this.beanName = name;
}
protected abstract @Nullable D addRegistration(String description, ServletContext servletContext);
protected void configure(D registration) {
registration.setAsyncSupported(this.asyncSupported);
if (!this.initParameters.isEmpty()) {
registration.setInitParameters(this.initParameters);
}
}
/**
* Deduces the name for this registration. Will return user specified name or fallback
* to the bean name. If the bean name is not available, convention based naming is
* used.
* @param value the object used for convention based names
* @return the deduced name
*/
protected final String getOrDeduceName(@Nullable Object value) {
if (this.name != null) {
return this.name;
}
if (this.beanName != null) {
return this.beanName;
}
if (value == null) {
return "null";
}
return Conventions.getVariableName(value);
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free