Spring Boot Migration - yibinericxia/documents GitHub Wiki
Migration from 1.x to 2.x
Please check your spring boot version and upgrade it to the 1.5.8 first before migrating it to 2.x. The following is the list of items for 1.5.8 migration
- package versions
plugin: sprint-boot
spring-boot-gradle-plugin: 1.3.x
=>
plugin: org.springframework.boot
spring-boot-gradle-plugin: 1.5.22.RELEASE
- application properties
spring.resources.cache.cachecontrol.*=xxx
=>
spring.web.resources.cache.cachecontrol.*=xxx
The following is the list of changes for 2.x migration:
- Sort & PageRequest
Sort.Direction direction = Sort.Direction.fromStringOrNull(aString);
Sort sort = new Sort(direction, properties);
PageRequest pr = new PageRequest(page, size, sort);
=>
Sort.Direction direction = Sort.Direction.fromOptionalString(aString);
Sort sort = Sort.by(direction, properties);
PageRequest pr = PageRequest.of(page, size, sort);
- Repository related methods: findOne(id), findAll(ids), save(recordList), delete()
repo.findOne(id);
repo.findAll(ids);
repo.save(recordList);
repo.delete(id);
repo.delete(recordList);
=>
repo.findById(id);
repo.findAllById(ids);
repo.saveAll(recordList);
repo.deleteById(id);
repo.deletetAll(recordList);
- Query String
@Query("select * from myTable mt where mt.col1 != 'aString')
=>
@Query("select * from myTable mt where mt.col1 <> 'aString')
- ErrorController & ErrorAttributes from autoconfigure.web to web.servlet.error
RequestAttributes requestAttributes = new ServletRequestAttributes(httpServletRequest);
Map<String, Object> errorAttributeMap = errorAttributes.getErrorAttributes(requestAttributes, includeStackTrace);
=>
WebRequest webRequest = new ServletWebRequest(httpServletRequest);
Map<String, Object> errorAttributeMap = errorAttributes.getErrorAttributes(webRequest, includeStackTrace);
Migration from 2.x to 3.x
Please check your spring boot version and upgrade it to the 2.7.x first before migrating it to 3.x.
Depending on the spring boot version of 3.x.x, you may need to migrate Java to 17/21 and replace some packages like sleuth with Micrometer along with Observation support for the previous instrumentation.
Hibernate from 4.x to 5.x
SequenceGenerator needs to be placed by SequenceStyleGenerator (normally the default allocation size is 50)
@SequenceGenerator(name = "THE_TABLE_GENERATOR", sequenceName = "SEQ_THE_TABLE", allocationSize = x)
=>
@GenericGenerator(
name = "THE_TABLE_GENERATOR",
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
parameters = {
@Parameter(name = "sequence_name", value = "SEQ_THE_TABLE"),
@Parameter(name = "increment_size", value = "x")
}
)