- Use
@ConfigurationProperties
and always get state from the bean. - The
Environment
can change at runtime and Spring Cloud does this for you usingRefreshEvent
. - Changes are propagated to beans in Spring Cloud in 2 ways (
@ConfigurationProperties
and@RefreshScope
). - If you care about the state of
@ConfigurationProperties
being consistent on concurrent access, put it or the consumer@Bean
in@RefreshScope
.
When a Spring Boot app starts up with default (INFO) logging, there are some noticeable gaps (pauses). It's worth focusing on the gaps when looking for efficiency savings because of the amount of time they take, and because no-one bothered to log anything, so the chances are the app is doing something repetitive. We can tweak the logging levels to try and fill in the gaps and find out what is going on in there.
Basic empty web app with actuators has three such gaps:
0 1410ms
|------|---------------------------|-----|------|---------|--------|--------|
| 578 | |144(5)| | 133(6) |
.classpath | |
.project | |
.settings | |
target | |
bin | |
*/src/META-INF/ | |
*/src/main/java/META-INF/ | |
samples/*/*/src/main/webapp/META-INF/ | |
target/ | |
.classpath | |
.project | |
.DS_Store | |
.settings/ | |
*.iml | |
*.iws |
<?xml version="1.0" encoding="UTF-8"?> | |
<classpath> | |
<classpathentry kind="src" path="src/main/resources"/> | |
<classpathentry kind="src" path="src/main/java"/> | |
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/> | |
<classpathentry kind="src" path="src/test/resources"/> | |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | |
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"> | |
<attributes> | |
<attribute name="org.eclipse.jst.component.nondependency" value=""/> |
<?xml version="1.0" encoding="UTF-8"?> | |
<classpath> | |
<classpathentry kind="src" path="src/main/resources"/> | |
<classpathentry kind="src" path="src/main/java"/> | |
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/> | |
<classpathentry kind="src" path="src/test/resources"/> | |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | |
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> | |
<classpathentry kind="output" path="target/classes"/> | |
</classpath> |
.cache | |
target/ | |
*~ | |
#* | |
*# | |
*/src/main/*/META-INF/ | |
*/src/main/*/WEB-INF/lib/ | |
.access_token | |
.result | |
.classpath |
class | method | sample | beans | classes | heap | memory | median | mean | range |
---|---|---|---|---|---|---|---|---|---|
com.example.bench.MicroBenchmark | main | demo | 100.000 | 4671.000 | 7.401 | 47.829 | 0.747 | 0.758 | 0.011 |
This project is a minimal setup depending only on spring-context
but
mimicking closely the mess that you get into with
@EnableTransactionManagement
(spring-tx
) or
@EnableGlobalMethodSecurity
(spring-security
). These annotations
lead to registration of an InfrastructureAdvisorAutoProxyCreator
which is responsible for locating the Advisor
bean that provides the
enabled feature. The mess is caused by aggressive bean instantiation
in that component which can cause cascades of unsafe bean instantation
Spring Cloud Function has had support for Microsoft Azure Functions since version 1.0, but in the latest 2.0 releases (still in milestone phase) we decided to change the programming model a bit. This article describes what the changes mean for users, and provides a bit of background behind the shift. We in the Spring team had a lot of fun working on this and collaborating with the folks at Microsoft to get