Togglz support with Spring boot 3 - spring

I am adding Togglz to my existing spring boot 3 application. I can not read the state of the enum constants from application.yml or any other property files. Only way state can be changed is by annotating #EnableByDefault. I followed the link https://www.baeldung.com/spring-togglz for reference implementation.
Has anyone successfully configured Togglz with Spring Boot3?

Related

where does spring load the auto configuration files from

I have read some tutorial on old version of spring boot.
https://www.logicbig.com/tutorials/spring-framework/spring-boot/auto-config-mechanism.html
The boot configuration classes are loaded from
spring-boot-autoconfigure-1.4.2.RELEASE.jar!/META-INF/spring.factories
(in the file, search for the key
org.springframework.boot.autoconfigure.EnableAutoConfiguration)
https://github.com/spring-projects/spring-boot/blob/v1.4.4.RELEASE/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories It has "org.springframework.boot.autoconfigure.EnableAutoConfiguration"
My understanding is that spring loads/runs all these files defined by EnableAutoConfiguration in spring.factories. If the #Conditional* matches, the bean will be created.
But in the last 2.x version, there is no such property EnableAutoConfiguration
https://github.com/spring-projects/spring-boot/blob/2.7.x/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
where does spring load the auto configuration files from?
Updated:
I found them here:
https://github.com/spring-projects/spring-boot/blob/v2.7.4/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
Spring Boot 2.7 introduced a new ‘META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports’ file for registering auto-configurations, while maintaining backwards compatibility with registration in ‘spring.factories’. With Spring Boot 3.0 release, support for registering auto-configurations in ‘spring.factories’ has been removed in favor of the imports file.
we are using #SpringBootApplication annotations on spring boot project main class in which they have all others annotations.

How Spring Boot autoconfigures the JCache when there is no JCache configuration file entry in spring.factories file?

I am new to spring boot project.
Currently I am working on a project with spring boot, Jcache with ehcache implementation.
I am trying to understand how spring boot autoconfigures the Cache Framework. I did my own research and identified spring boot #EnableAutoConfiguration reads the spring.factories file and autoconfigures the Cache related beans based on the classes available in classpath.
Here is the Spring Boot Cache auto configure Java based Configuration file available under spring.factories file
org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\
but for Jcache “ JCacheCacheConfiguration.java” is the Spring Boot auto configuration file , But this file is not available under spring.factroies file in autoconfigurer.jar file.
Then how spring boot auto configures the Jcache without entry in spring.factories file?
JCache implementations are providing a service (in META-INF). So Spring can found the implementation magically. The simpler is #EnableCaching which will find the provider and give you caching right away.
Then, you will want to provide a specific caching configuration. The easiest is by specifying spring.cache.jcache.config=ehcache.xml in your application.properties.
That's it. You will find a more complicated and Java (no xml) configuration in ehcache sample and pet clinic.

What are the differences between spring security providers? (Spring Roo 2 M3)

Well i'm building some personal project to learn spring roo 2. Now i'm struggling with spring security. There is little information about spring roo 2 in google and many relatively useful information on spring boot relating to spring roo.
with the command "security setup" you got the "--provider" option.
This is the description that the help gives you:
optional --provider: The Spring Security provider to install. Possible values are: DEFAULT (default Spring Security configuration provided by Spring Boot will be used), and SPRINGLETS_JPA (advanced Spring Security configuration will be included using Springlets JPA Authentication).; default: 'DEFAULT'
I couldn't find the difference between these two options, even on the spring roo M3 reference documentation. Even searching for "Springlets JPA Authentication" gives no information about it.
Anyone has any clue about this?
Thanks
These are the main differences between this two providers:
DEFAULT: Is the default Spring Security auto-configuration provided by Spring Boot when you include the spring-boot-starter-security in your project classpath. This is the default option because Spring Roo always tries to generate applications that use the auto-configuration provided by Spring Boot.
Selecting this provided the following changes will be applied to your project:
spring-boot-starter-security dependency will be included to your pom.xml file
If you want to know more information about this configuration you should check the spring boot reference guide
SPRINGLETS_JPA: If you select this provider, the default Spring Security auto-configuration provided by Spring Boot will be used. In addition, this provider will include the Springlets library to your classpath that provides you some extra starters to auto-configure advanced Spring Security properties. Also, configures the security authentication to use and user from the database instead of the default in-memory authentication provided by Spring Boot auto-configuration. You will be able to manage these configuration using the application.properties file and including the properties springlets.security.auth.in-memory.enabled and springlets.security.auth.in-memory.erase-credentials.
Selecting this provided the following changes will be applied to your project:
springlets-boot-starter-authentication dependency will be included to your pom.xml file
security.enable-csrf=true property will be included to enable CSRF. Know more about CSRF and Spring Security here
To know more about the Springlets Security project check the Springlets project page
Hope it helps,

Default Spring Boot log4j2 log pattern

Spring boot ships with several default logging framework configurations including Log4j2. While there is detailed documentation about logging in the Spring boot reference manual it does not mention how and where exactly the default log pattern is configured, which makes it difficult to override this.
The question is where does Spring Boot configure the default log pattern of for Log4j2?
So far I have looked in the following places of Spring Boot:
AutoConfigurationReportLoggingInitializer
LoggingApplicationListener
SimpleFormatter
LoggingSystem
Log4J2LoggingSystem
It seems the Log4J2 configuration is not done in any Java class so I was looking at the wrong place. Spring Boot ships with two files log4j2.xml and log4j2-file.xml which contain the default configuration and can be found in org.springframework.boot.logging.log4j2.

Minimum version of spring for spring-boot v 1.3

I have an existing spring application built using spring framework version 3.1.2. I am trying to create a spring-boot application out of this existing application, but getting some dependency issues. So just wondering, what is the spring framework version, that is supported by spring-boot v 1.3.0.
Or to put it in another words, is it possible to have a spring-boot application from a spring 3.1.2 based application?
Spring boot has hard dependencies on classes in Spring 4 and could not be configured to work with Spring 3. If you are really interested in using Spring Boot the only way you can do this is to follow a migration path to Spring 4 and then add Spring Boot to your application.
It is worth mentioning that the "boot" in Spring Boot is meant to be short for bootstrapping, as in initial setup of an application. I'm not saying there would be zero benefits from migrating from Spring 4 vanilla to Spring Boot. But make sure you are migrating for the right reasons the main purpose of Spring Boot is easy bootstrapping of applications but here are some other features which might be worth making the move.
Spring Boot dev-tools (Auto restart on code changes)
Awesome spring boot plugins for maven and gradle to ease upgrading spring in the future (hint it upgrades many other dependencies for you)
Bootstrapping new features such as MongoDb through auto-configuration.
Migration from 3.1 to 3.2
https://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/migration-3.2.html
Migration from Spring 3 to Spring 4.
https://spring.io/blog/2014/01/30/migrating-from-spring-framework-3-2-to-4-0-1
There are many features in spring boot that are dependent upon new features added to Spring 4. One primary example is the new list of annotations added to Spring 4 that allow conditional wiring/loading of beans. Which is the primary method of wiring configurations in a plugin-like way.
For example lets see the AutoConfiguration class for the H2 console
https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java
The first thing we see is it's wired to be a Configuration class. It will only load if WebServlet.class is on the classpath and if the property spring.h2.console is = true. It is also configured to load SecurityAutoConfiguration first as this is a dependency at least for securing the h2 console page.
#Configuration
#ConditionalOnWebApplication
#ConditionalOnClass(WebServlet.class)
#ConditionalOnProperty(prefix = "spring.h2.console", name = "enabled", havingValue = "true", matchIfMissing = false)
#EnableConfigurationProperties(H2ConsoleProperties.class)
#AutoConfigureAfter(SecurityAutoConfiguration.class)
public class H2ConsoleAutoConfiguration {
When this Configuration is loaded it will check these conditions and upon all conditions being true then and only then will it load in the beans defined in the class. In this case it wires the h2console servlet.
#Bean
public ServletRegistrationBean h2Console() {
String path = this.properties.getPath();
String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
return new ServletRegistrationBean(new WebServlet(), urlMapping);
}
There is also the security configuration in that class which introduces one more concept of conditionally loading a configuration based on another class being loaded into the context. These annotations do not always need to be on a Configuration level but can also apply to the bean level.
These concepts are core to how Spring Boot is implemented and therefore could not work with Spring 3.
Spring 3 list of annotations
http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/context/annotation/
Spring 4 Conditional Annotations
https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/
Thanks Zergleb for posting detailed answer. I found a way to run the spring 3 app as an independent jar by created an uber jar with a little instrumentation to bootstrap spring through a java class.
It is explained nicely in a short post at https://mihhaillapushkin.wordpress.com/2013/02/18/spring-3-for-standalone-applications

Resources