Skip to content

Commit ae057cb

Browse files
committed
Use constructor injection
1 parent d13b510 commit ae057cb

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

web/src/main/java/software/xdev/sse/web/cookie/DefaultCookieSecureService.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
*/
1616
package software.xdev.sse.web.cookie;
1717

18-
import jakarta.annotation.PostConstruct;
19-
2018
import org.slf4j.Logger;
2119
import org.slf4j.LoggerFactory;
22-
import org.springframework.beans.factory.annotation.Value;
2320

2421

2522
public class DefaultCookieSecureService implements CookieSecureService
@@ -33,12 +30,11 @@ public class DefaultCookieSecureService implements CookieSecureService
3330
* https://www.baeldung.com/spring-security-session
3431
* </a>
3532
*/
36-
@Value("${server.servlet.session.cookie.secure:true}")
37-
private boolean secure;
33+
private final boolean secure;
3834

39-
@PostConstruct
40-
protected void postConstruct()
35+
public DefaultCookieSecureService(final boolean secure)
4136
{
37+
this.secure = secure;
4238
if(!this.secure)
4339
{
4440
LOG.info("Cookies will NOT be secured (as defined in 'server.servlet.session.cookie.secure')");

web/src/main/java/software/xdev/sse/web/cookie/auto/CookieAutoConfig.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package software.xdev.sse.web.cookie.auto;
1717

18+
import org.springframework.beans.factory.annotation.Value;
1819
import org.springframework.boot.autoconfigure.AutoConfiguration;
1920
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2021
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -31,9 +32,10 @@ public class CookieAutoConfig
3132
{
3233
@ConditionalOnMissingBean
3334
@Bean
34-
public CookieSecureService cookieSecureService()
35+
public CookieSecureService cookieSecureService(
36+
@Value("${server.servlet.session.cookie.secure:true}") final boolean secure)
3537
{
36-
return new DefaultCookieSecureService();
38+
return new DefaultCookieSecureService(secure);
3739
}
3840

3941
@ConditionalOnMissingBean

0 commit comments

Comments
 (0)