31
31
import org .springframework .core .env .ConfigurableEnvironment ;
32
32
import org .springframework .core .env .Environment ;
33
33
import org .springframework .core .env .MapPropertySource ;
34
+ import org .springframework .util .ClassUtils ;
34
35
35
36
/**
36
37
* {@link EnvironmentPostProcessor} to add properties that make sense when working at
@@ -49,6 +50,12 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
49
50
50
51
private static final String ENABLED = "spring.devtools.add-properties" ;
51
52
53
+ private static final String WEB_LOGGING = "logging.level.web" ;
54
+
55
+ private static final String [] WEB_ENVIRONMENT_CLASSES = {
56
+ "org.springframework.web.context.ConfigurableWebEnvironment" ,
57
+ "org.springframework.boot.web.reactive.context.ConfigurableReactiveWebEnvironment" };
58
+
52
59
private static final Map <String , Object > PROPERTIES ;
53
60
54
61
static {
@@ -66,18 +73,24 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
66
73
properties .put ("server.error.include-stacktrace" , "ALWAYS" );
67
74
properties .put ("server.servlet.jsp.init-parameters.development" , "true" );
68
75
properties .put ("spring.reactor.stacktrace-mode.enabled" , "true" );
69
- properties .put ("logging.level.web" , "debug" );
70
76
PROPERTIES = Collections .unmodifiableMap (properties );
71
77
}
72
78
73
79
@ Override
74
80
public void postProcessEnvironment (ConfigurableEnvironment environment ,
75
81
SpringApplication application ) {
76
- if (isLocalApplication (environment ) && canAddProperties (environment )) {
77
- logger .info ("Devtools property and logging defaults active! Set '" + ENABLED
78
- + "' to 'false' to disable" );
79
- environment .getPropertySources ()
80
- .addLast (new MapPropertySource ("devtools" , PROPERTIES ));
82
+ if (isLocalApplication (environment )) {
83
+ if (canAddProperties (environment )) {
84
+ logger .info ("Devtools property defaults active! Set '" + ENABLED
85
+ + "' to 'false' to disable" );
86
+ environment .getPropertySources ()
87
+ .addLast (new MapPropertySource ("devtools" , PROPERTIES ));
88
+ }
89
+ if (isWebApplication (environment )
90
+ && !environment .containsProperty (WEB_LOGGING )) {
91
+ logger .info ("For additional web related logging consider "
92
+ + "setting the '" + WEB_LOGGING + "' property to 'DEBUG'" );
93
+ }
81
94
}
82
95
}
83
96
@@ -106,4 +119,15 @@ private boolean isRemoteRestartEnabled(Environment environment) {
106
119
return environment .containsProperty ("spring.devtools.remote.secret" );
107
120
}
108
121
122
+ private boolean isWebApplication (Environment environment ) {
123
+ for (String candidate : WEB_ENVIRONMENT_CLASSES ) {
124
+ Class <?> environmentClass = ClassUtils .resolveClassName (candidate ,
125
+ environment .getClass ().getClassLoader ());
126
+ if (environmentClass != null && environmentClass .isInstance (environment )) {
127
+ return true ;
128
+ }
129
+ }
130
+ return false ;
131
+ }
132
+
109
133
}
0 commit comments