Quantcast
Channel: Baeldung
Viewing all articles
Browse latest Browse all 4535

Deprecated Classes in Spring

$
0
0

1. Introduction

In this tutorial, we’re going to take a look at the deprecated classes in Spring and Spring Boot and explain what these have been replaced with.

We’ll explore classes starting from Spring 4 and Spring Boot 1.4.

2. Deprecated Classes in Spring

For easier reading, we list classes and their replacements based on the Spring release. And, within each grouping of classes, we’ve sorted them by the class name, irrespective of package.

2.1. Spring 4.0.x

  • org.springframework.cache.interceptor.DefaultKeyGenerator  replaced by the SimpleKeyGenerator or custom KeyGenerator implementations based on hash codes
  • org.springframework.jdbc.support.lob.OracleLobHandler  DefaultLobHandler for the Oracle 10g driver and higher; we should consider it even against the Oracle 9i database
  • org.springframework.test.AssertThrows  we should make use of JUnit 4’s @Test(expected=…) support instead
  • org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter  AllEncompassingFormHttpMessageConverter

The following class was deprecated as of Spring 4.0.2, in favor of CGLIB 3.1’s default strategy, and was removed in Spring 4.1:

  • org.springframework.cglib.transform.impl.MemorySafeUndeclaredThrowableStrategy

All deprecated classes, as well as deprecated interfaces, fields, methods, constructors, and enum constants for this Spring version can be found on the official documentation page.

2.2. Spring 4.1.x

  • org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper  BeanPropertyRowMapper
  • org.springframework.jdbc.core.simple.ParameterizedSingleColumnRowMapper  SingleColumnRowMapper

We can find the full list in the Spring 4.1.x JavaDoc.

2.3. Spring 4.2.x

  • org.springframework.web.servlet.view.document.AbstractExcelView  AbstractXlsView and its AbstractXlsxView and AbstractXlsxStreamingView variants
  • org.springframework.format.number.CurrencyFormatter  CurrencyStyleFormatter
  • org.springframework.messaging.simp.user.DefaultUserSessionRegistry  we should use the SimpUserRegistry in combination with the ApplicationListener listening for the AbstractSubProtocolEvent events
  • org.springframework.messaging.handler.HandlerMethodSelector  generalized and refined MethodIntrospector
  • org.springframework.core.JdkVersion   we should perform direct checks for the desired JDK API variants via reflection
  • org.springframework.format.number.NumberFormatter  NumberStyleFormatter
  • org.springframework.format.number.PercentFormatter  PercentStyleFormatter
  • org.springframework.test.context.transaction.TransactionConfigurationAttributes  this class is removed along with the @TransactionConfiguration in Spring 5
  • org.springframework.oxm.xmlbeans.XmlBeansMarshaller  following the XMLBeans retirement at Apache

The following classes are deprecated in favor of Apache Log4j 2:

  • org.springframework.web.util.Log4jConfigListener
  • org.springframework.util.Log4jConfigurer
  • org.springframework.web.filter.Log4jNestedDiagnosticContextFilter
  • org.springframework.web.context.request.Log4jNestedDiagnosticContextInterceptor
  • org.springframework.web.util.Log4jWebConfigurer

More details are available in the Spring 4.2.x JavaDoc.

2.4. Spring 4.3.x

This version of Spring brought lots of deprecated classes:

  • org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice  this class is removed in Spring Framework 5.1; we should use CORS instead
  • org.springframework.oxm.castor.CastorMarshaller  deprecated due to the lack of activity on the Castor project
  • org.springframework.web.servlet.mvc.method.annotation.CompletionStageReturnValueHandler  DeferredResultMethodReturnValueHandler, which now supports CompletionStage return values via an adapter mechanism
  • org.springframework.jdbc.support.incrementer.DB2MainframeSequenceMaxValueIncrementer  renamed to Db2MainframeMaxValueIncrementer
  • org.springframework.jdbc.support.incrementer.DB2SequenceMaxValueIncrementer  renamed to Db2LuwMaxValueIncrementer
  • org.springframework.core.GenericCollectionTypeResolver  deprecated in favor of direct ResolvableType usage
  • org.springframework.web.servlet.mvc.method.annotation.ListenableFutureReturnValueHandler  DeferredResultMethodReturnValueHandler, which now supports ListenableFuture return values via an adapter mechanism
  • org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer  we should use PostgresSequenceMaxValueIncrementer instead
  • org.springframework.web.servlet.ResourceServlet  ResourceHttpRequestHandler

These classes are deprecated in favor of the HandlerMethod-based MVC infrastructure:

  • org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping
  • org.springframework.web.bind.annotation.support.HandlerMethodInvoker
  • org.springframework.web.bind.annotation.support.HandlerMethodResolver

Several classes are deprecated in favor of annotation-driven handler methods:

  • org.springframework.web.servlet.mvc.support.AbstractControllerUrlHandlerMapping
  • org.springframework.web.servlet.mvc.multiaction.AbstractUrlMethodNameResolver
  • org.springframework.web.servlet.mvc.support.ControllerBeanNameHandlerMapping
  • org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver
  • org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver
  • org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver

There are also a lot of classes from Spring that we should replace with their Hibernate 4.x/5.x equivalents:

  • org.springframework.orm.hibernate3.support.AbstractLobType
  • org.springframework.orm.hibernate3.AbstractSessionFactoryBean
  • org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
  • org.springframework.orm.hibernate3.support.BlobByteArrayType
  • org.springframework.orm.hibernate3.support.BlobSerializableType
  • org.springframework.orm.hibernate3.support.BlobStringType
  • org.springframework.orm.hibernate3.support.ClobStringType
  • org.springframework.orm.hibernate3.FilterDefinitionFactoryBean
  • org.springframework.orm.hibernate3.HibernateAccessor
  • org.springframework.orm.hibernate3.support.HibernateDaoSupport
  • org.springframework.orm.hibernate3.HibernateExceptionTranslator
  • org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean
  • org.springframework.orm.hibernate3.HibernateTemplate
  • org.springframework.orm.hibernate3.HibernateTransactionManager
  • org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener
  • org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
  • org.springframework.orm.hibernate3.LocalJtaDataSourceConnectionProvider
  • org.springframework.orm.hibernate3.LocalRegionFactoryProxy
  • org.springframework.orm.hibernate3.LocalSessionFactoryBean
  • org.springframework.orm.hibernate3.LocalTransactionManagerLookup
  • org.springframework.orm.hibernate3.support.OpenSessionInterceptor
  • org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
  • org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor
  • org.springframework.orm.hibernate3.support.ScopedBeanInterceptor
  • org.springframework.orm.hibernate3.SessionFactoryUtils
  • org.springframework.orm.hibernate3.SessionHolder
  • org.springframework.orm.hibernate3.SpringSessionContext
  • org.springframework.orm.hibernate3.SpringTransactionFactory
  • org.springframework.orm.hibernate3.TransactionAwareDataSourceConnectionProvider
  • org.springframework.orm.hibernate3.TypeDefinitionBean

Several classes are deprecated in favor of FreeMarker:

  • org.springframework.web.servlet.view.velocity.VelocityConfigurer
  • org.springframework.ui.velocity.VelocityEngineFactory
  • org.springframework.ui.velocity.VelocityEngineFactoryBean
  • org.springframework.ui.velocity.VelocityEngineUtils
  • org.springframework.web.servlet.view.velocity.VelocityLayoutView
  • org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver
  • org.springframework.web.servlet.view.velocity.VelocityToolboxView
  • org.springframework.web.servlet.view.velocity.VelocityView
  • org.springframework.web.servlet.view.velocity.VelocityViewResolver

These classes are removed in Spring Framework 5.1, and we should use other transports instead:

  • org.springframework.web.socket.sockjs.transport.handler.JsonpPollingTransportHandler
  • org.springframework.web.socket.sockjs.transport.handler.JsonpReceivingTransportHandler

Finally, there are also a couple of classes without an appropriate replacement:

  • org.springframework.core.ControlFlowFactory
  • org.springframework.util.WeakReferenceMonitor

As usual, the Spring 4.3.x JavaDoc contains the complete list.

2.5. Spring 5.0.x

  • org.springframework.web.reactive.support.AbstractAnnotationConfigDispatcherHandlerInitializer  deprecated in favor of AbstractReactiveWebInitializer
  • org.springframework.web.util.AbstractUriTemplateHandler  DefaultUriBuilderFactory
  • org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer   deprecated in favor of simply using the WebSocketMessageBrokerConfigurer, which has default methods, made possible by a Java 8 baseline
  • org.springframework.web.client.AsyncRestTemplate   WebClient
  • org.springframework.web.context.request.async.CallableProcessingInterceptorAdapter   deprecated since the CallableProcessingInterceptor has default methods
  • org.springframework.messaging.support.ChannelInterceptorAdapter   deprecated since the ChannelInterceptor has default methods (made possible by a Java 8 baseline) and can be implemented directly without the need for this no-op adapter
  • org.springframework.util.comparator.CompoundComparator  deprecated in favor of the standard JDK 8 Comparator.thenComparing(Comparator)
  • org.springframework.web.util.DefaultUriTemplateHandler   DefaultUriBuilderFactory; we should note that the DefaultUriBuilderFactory has a different default value for the parsePath property (changed from false to true)
  • org.springframework.web.context.request.async.DeferredResultProcessingInterceptorAdapter   since the DeferredResultProcessingInterceptor has default methods
  • org.springframework.util.comparator.InvertibleComparator   deprecated in favor of the standard JDK 8 Comparator.reversed()
  • org.springframework.http.client.Netty4ClientHttpRequestFactory   deprecated in favor of ReactorClientHttpConnector
  • org.apache.commons.logging.impl.SimpleLog   moved to spring-jcl (effectively equivalent to NoOpLog)
  • org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter   WebMvcConfigurer has default methods (made possible by a Java 8 baseline) and can be implemented directly without the need for this adapter
  • org.springframework.beans.factory.config.YamlProcessor.StrictMapAppenderConstructor   superseded by SnakeYAML’s own duplicate key handling

We have two classes deprecated in favor of AbstractReactiveWebInitializer:

  • org.springframework.web.reactive.support.AbstractDispatcherHandlerInitializer
  • org.springframework.web.reactive.support.AbstractServletHttpHandlerAdapterInitializer

And, the following classes don’t have replacements:

  • org.springframework.http.client.support.AsyncHttpAccessor
  • org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory
  • org.springframework.http.client.InterceptingAsyncClientHttpRequestFactory
  • org.springframework.http.client.support.InterceptingAsyncHttpAccessor
  • org.springframework.mock.http.client.MockAsyncClientHttpRequest

The complete list is available in the Spring 5.0.x JavaDoc.

2.6. Spring 5.1.x

  • org.springframework.http.client.support.BasicAuthorizationInterceptor   deprecated in favor of BasicAuthenticationInterceptor, which reuses the HttpHeaders.setBasicAuth(java.lang.String, java.lang.String) and now shares its default charset ISO-8859-1 instead of using UTF-8 as it did previously
  • org.springframework.jdbc.core.BatchUpdateUtils   no longer used by the JdbcTemplate
  • org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials   we should use the HttpHeaders.setBasicAuth(String, String) method while building the request
  • org.springframework.web.filter.reactive.ForwardedHeaderFilter   this filter is deprecated in favor of using the ForwardedHeaderTransformer, which can be declared as a bean with the name “forwardedHeaderTransformer” or registered explicitly in the WebHttpHandlerBuilder
  • org.springframework.jdbc.core.namedparam.NamedParameterBatchUpdateUtils   not used by the NamedParameterJdbcTemplate any more
  • org.springframework.core.io.PathResource   FileSystemResource.FileSystemResource(Path)
  • org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor   we should use constructor injection for required settings (or a custom InitializingBean implementation)
  • org.springframework.remoting.caucho.SimpleHessianServiceExporter   HessianServiceExporter
  • org.springframework.remoting.httpinvoker.SimpleHttpInvokerServiceExporter   HttpInvokerServiceExporter
  • org.springframework.remoting.support.SimpleHttpServerFactoryBean   embedded Tomcat/Jetty/Undertow
  • org.springframework.remoting.jaxws.SimpleHttpServerJaxWsServiceExporter   SimpleJaxWsServiceExporter

These are deprecated in favor of EncodedResourceResolver:

  • org.springframework.web.reactive.resource.GzipResourceResolver
  • org.springframework.web.servlet.resource.GzipResourceResolver

There are several classes that are deprecated in favor of Java EE 7’s DefaultManagedTaskScheduler:

  • org.springframework.scheduling.commonj.DelegatingTimerListener
  • org.springframework.scheduling.commonj.ScheduledTimerListener
  • org.springframework.scheduling.commonj.TimerManagerAccessor
  • org.springframework.scheduling.commonj.TimerManagerFactoryBean
  • org.springframework.scheduling.commonj.TimerManagerTaskScheduler

And, a few are deprecated in favor of Java EE 7’s DefaultManagedTaskExecutor:

  • org.springframework.scheduling.commonj.DelegatingWork
  • org.springframework.scheduling.commonj.WorkManagerTaskExecutor

Finally, one class is deprecated without a substitute:

  • org.apache.commons.logging.LogFactoryService

For more details, please see the official Spring 5.1.x JavaDoc on deprecated classes.

3. Deprecated Classes in Spring Boot

Now, let’s take a look at the deprecated classes in Spring Boot back to version 1.4.

We should note here that, for Spring Boot 1.4 and 1.5, most of the replacement classes kept their original names but have been moved to different packages. Therefore, we use fully qualified class names in the next two subsections for both the deprecated and replacement classes.

3.1. Spring Boot 1.4.x

  • org.springframework.boot.actuate.system.ApplicationPidFileWriter   deprecated in favor of org.springframework.boot.system.ApplicationPidFileWriter
  • org.springframework.boot.yaml.ArrayDocumentMatcher   deprecated in favor of exact String-based matching
  • org.springframework.boot.test.ConfigFileApplicationContextInitializer   org.springframework.boot.test.context.ConfigFileApplicationContextInitializer
  • org.springframework.boot.yaml.DefaultProfileDocumentMatcher   it is no longer used
  • org.springframework.boot.context.embedded.DelegatingFilterProxyRegistrationBean   org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean
  • org.springframework.boot.actuate.system.EmbeddedServerPortFileWriter   org.springframework.boot.system.EmbeddedServerPortFileWriter
  • org.springframework.boot.test.EnvironmentTestUtils   org.springframework.boot.test.util.EnvironmentTestUtils
  • org.springframework.boot.context.embedded.ErrorPage   org.springframework.boot.web.servlet.ErrorPage
  • org.springframework.boot.context.web.ErrorPageFilter   org.springframework.boot.web.support.ErrorPageFilter
  • org.springframework.boot.context.embedded.FilterRegistrationBean   org.springframework.boot.web.servlet.FilterRegistrationBean
  • org.springframework.boot.test.IntegrationTestPropertiesListener   it is no longer used by the @IntegrationTest
  • org.springframework.boot.context.embedded.MultipartConfigFactory   org.springframework.boot.web.servlet.MultipartConfigFactory
  • org.springframework.boot.context.web.OrderedCharacterEncodingFilter   org.springframework.boot.web.filter.OrderedCharacterEncodingFilter
  • org.springframework.boot.context.web.OrderedHiddenHttpMethodFilter   org.springframework.boot.web.filter.OrderedHiddenHttpMethodFilter
  • org.springframework.boot.context.web.OrderedHttpPutFormContentFilter   org.springframework.boot.web.filter.OrderedHttpPutFormContentFilter
  • org.springframework.boot.context.web.OrderedRequestContextFilter   org.springframework.boot.web.filter.OrderedRequestContextFilter
  • org.springframework.boot.test.OutputCapture   org.springframework.boot.test.rule.OutputCapture
  • org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer
  • org.springframework.boot.context.web.ServletContextApplicationContextInitializer   org.springframework.boot.web.support.ServletContextApplicationContextInitializer
  • org.springframework.boot.context.embedded.ServletListenerRegistrationBean   org.springframework.boot.web.servlet.ServletListenerRegistrationBean
  • org.springframework.boot.context.embedded.ServletRegistrationBean   org.springframework.boot.web.servlet.ServletRegistrationBean
  • org.springframework.boot.test.SpringApplicationContextLoader   deprecated in favor of @SpringBootTest; if necessary, we may also use the org.springframework.boot.test.context.SpringBootContextLoader
  • org.springframework.boot.test.SpringBootMockServletContext   org.springframework.boot.test.mock.web.SpringBootMockServletContext
  • org.springframework.boot.context.web.SpringBootServletInitializer   org.springframework.boot.web.support.SpringBootServletInitializer
  • org.springframework.boot.test.TestRestTemplate   org.springframework.boot.test.web.client.TestRestTemplate

Since Velocity support is deprecated in Spring Framework 4.3, the following classes are also deprecated in Spring Boot:

  • org.springframework.boot.web.servlet.view.velocity.EmbeddedVelocityViewResolver
  • org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration
  • org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration.VelocityConfiguration
  • org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration.VelocityNonWebConfiguration
  • org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration.VelocityWebConfiguration
  • org.springframework.boot.autoconfigure.velocity.VelocityProperties
  • org.springframework.boot.autoconfigure.velocity.VelocityTemplateAvailabilityProvider

The Spring Boot 1.4.x JavaDoc has the full list.

3.2. Spring Boot 1.5.x

  • org.springframework.boot.context.event.ApplicationStartedEvent   deprecated in favor of org.springframework.boot.context.event.ApplicationStartingEvent
  • org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector   deprecated in favor of org.springframework.boot.autoconfigure.AutoConfigurationImportSelector
  • org.springframework.boot.actuate.cache.GuavaCacheStatisticsProvider   following the removal of Guava support in Spring Framework 5
  • org.springframework.boot.loader.tools.Layouts.Module   deprecated in favor of a custom LayoutFactory
  • org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration   deprecated in favor of org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration
  • org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration   deprecated in favor of org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
  • org.springframework.boot.actuate.autoconfigure.ShellProperties   deprecated since CRaSH is not actively maintained

These two classes are deprecated since CRaSH is not actively maintained:

  • org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration
  • org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration.AuthenticationManagerAdapterConfiguration

There also a few classes without a replacement:

  • org.springframework.boot.autoconfigure.cache.CacheProperties.Hazelcast
  • org.springframework.boot.autoconfigure.jdbc.metadata.CommonsDbcpDataSourcePoolMetadata
  • org.springframework.boot.autoconfigure.mustache.MustacheCompilerFactoryBean

To see the entire list of what was deprecated, we can consult the official Spring Boot 1.5.x JavaDoc site.

3.3. Spring Boot 2.0.x

  • org.springframework.boot.test.util.EnvironmentTestUtils   deprecated in favor of TestPropertyValues
  • org.springframework.boot.actuate.metrics.web.reactive.server.RouterFunctionMetrics   deprecated in favor of the auto-configured MetricsWebFilter

And one class doesn’t have a substitute:

  • org.springframework.boot.actuate.autoconfigure.couchbase.CouchbaseHealthIndicatorProperties

Please check out the deprecated list for Spring Boot 2.0.x for more details.

3.4. Spring Boot 2.1.x

  • org.springframework.boot.actuate.health.CompositeHealthIndicatorFactory   deprecated in favor of CompositeHealthIndicator.CompositeHealthIndicator(HealthAggregator, HealthIndicatorRegistry)
  • org.springframework.boot.actuate.health.CompositeReactiveHealthIndicatorFactory   deprecated in favor of CompositeReactiveHealthIndicator.CompositeReactiveHealthIndicator(HealthAggregator, ReactiveHealthIndicatorRegistry)

Finally, we can consult the complete list of deprecated classes and interfaces in Spring Boot 2.1.x.

4. Conclusion

In this tutorial, we explored deprecated classes in Spring since version 4 and Spring Boot from version 1.4, along with their corresponding replacements, where available.


Viewing all articles
Browse latest Browse all 4535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>