wimdeblauwe / htmx-spring-boot

Spring Boot and Thymeleaf helpers for working with htmx
Apache License 2.0
436 stars 41 forks source link

Support for Spring Boot 3 (Spring 6) #26

Closed thombergs closed 1 year ago

thombergs commented 1 year ago

I was trying out this library with the current Spring Boot 3 milestone and got this error. The reason is that the library uses imports from org.thymeleaf.spring5 and these don't exist as a dependency in Spring Boot 3 anymore. Instead, the imports should be made from org.thymeleaf.spring6.

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'io.github.wimdeblauwe.hsbt.mvc.HtmxMvcConfiguration': Resolution of declared constructors on bean Class [io.github.wimdeblauwe.hsbt.mvc.HtmxMvcConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@1de0aca6] failed
    ...
Caused by: java.lang.NoClassDefFoundError: org/thymeleaf/spring5/view/ThymeleafViewResolver
    ...
wimdeblauwe commented 1 year ago

Hi Tom, thanks for informing me about this! I'll look into it later, but it won't be in the first coming weeks I am afraid.

checketts commented 1 year ago

@thombergs That sounds like we won't be able to support both Spring 5 and Spring 6 at the same time. Right?

wimdeblauwe commented 1 year ago

@thombergs I just pushed the branch spring-6-boot-3. If you build that locally using mvn install, then you could test it locally.

wimdeblauwe commented 1 year ago

The version number has been set to 2.0.0-SNAPSHOT for now. I would use 1.x for Spring 5 versions and 2.x for Spring 6 versions.

checketts commented 1 year ago

Heads up the the spring.factories config changed in Spring 3: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0.0-M5-Release-Notes#auto-configuration-registration

odrotbohm commented 1 year ago

Do you think we can have this rolled into a 2.0 M1 pretty soon? I have a lecture at Tu Dresden next week and would like to use this in a sample built on Spring Boot 3.

odrotbohm commented 1 year ago

Having snapshots deployed would help as well.

wimdeblauwe commented 1 year ago

@odrotbohm I will try to have a version this morning, but I am unable to fix the change away from spring.factories. I had this before:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  io.github.wimdeblauwe.hsbt.thymeleaf.HtmxThymeleafConfiguration,\
  io.github.wimdeblauwe.hsbt.mvc.HtmxMvcConfiguration
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc=\
  io.github.wimdeblauwe.hsbt.thymeleaf.HtmxThymeleafConfiguration,\
  io.github.wimdeblauwe.hsbt.mvc.HtmxMvcConfiguration

Which enabled the autoconfiguration on tests that use MockMvc (e.g. @WebMvcTest). How can I have this again in the new system?

wimdeblauwe commented 1 year ago

Never mind, just found it. I need to create a separate org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc.imports file now.

The wording in the release notes is a bit confusing:

If you have created your own test-slices, you should move the registration from spring.factories to the new place under META-INF/spring/.imports.

I am not creating my own test-slices, I am configuring extra classes on existing test slices like @WebMvcTest.

wimdeblauwe commented 1 year ago

@thombergs @odrotbohm You should be able to use version 2.0.0-M1 now with Spring Boot 3.0.0-M5: https://github.com/wimdeblauwe/htmx-spring-boot-thymeleaf/releases/tag/2.0.0-M1

odrotbohm commented 1 year ago

Th legacy auto-configuration format was removed in 3.0 M5. The release notes for 3.0 are a bit cluttered right now as we want folks to see what has changed for individual milestones until the GA release. After that, they'll be consolidated into a single document and the change is likely to be easier to find.

Thanks for the release, Wim!