refactor: Optimsed codes.

Move private and protected methods or fields to the last of java files.
This commit is contained in:
Zihlu Wang
2024-03-31 18:34:01 +08:00
parent cb537a6844
commit 5895557368
16 changed files with 200 additions and 152 deletions
@@ -65,19 +65,6 @@ import org.springframework.context.annotation.Bean;
@AutoConfigureAfter(value = GuidAutoConfiguration.class)
public class AuthzeroTokenResolverAutoConfiguration {
/**
* The GuidCreator instance to be used for generating JWT IDs (JTI).
*/
private final GuidCreator<?> jtiCreator;
/**
* The {@code SimpleJwtProperties} instance containing the configuration
* properties for Simple JWT.
*/
private final SimpleJwtProperties simpleJwtProperties;
private final ObjectMapper objectMapper;
/**
* Constructs a new {@code SimpleJwtAutoConfiguration} instance with the
* provided SimpleJwtProperties.
@@ -112,4 +99,17 @@ public class AuthzeroTokenResolverAutoConfiguration {
);
}
/**
* The GuidCreator instance to be used for generating JWT IDs (JTI).
*/
private final GuidCreator<?> jtiCreator;
/**
* The {@code SimpleJwtProperties} instance containing the configuration
* properties for Simple JWT.
*/
private final SimpleJwtProperties simpleJwtProperties;
private final ObjectMapper objectMapper;
}
@@ -39,6 +39,11 @@ import java.util.UUID;
@AutoConfiguration
public class GuidAutoConfiguration {
/**
* Create a default {@code jtiCreator} with UUID.
*
* @return UUID creator
*/
@Bean(name = "jtiCreator")
@Conditional(GuidCreatorCondition.class)
public GuidCreator<?> jtiCreator() {
@@ -65,17 +65,6 @@ import org.springframework.context.annotation.Bean;
@AutoConfigureAfter(value = GuidAutoConfiguration.class)
public class JjwtTokenResolverAutoConfiguration {
/**
* The GuidCreator instance to be used for generating JWT IDs (JTI).
*/
private final GuidCreator<?> jtiCreator;
/**
* The {@code SimpleJwtProperties} instance containing the configuration
* properties for Simple JWT.
*/
private final SimpleJwtProperties simpleJwtProperties;
/**
* Constructs a new {@code SimpleJwtAutoConfiguration} instance with the
* provided SimpleJwtProperties.
@@ -107,4 +96,15 @@ public class JjwtTokenResolverAutoConfiguration {
);
}
/**
* The GuidCreator instance to be used for generating JWT IDs (JTI).
*/
private final GuidCreator<?> jtiCreator;
/**
* The {@code SimpleJwtProperties} instance containing the configuration
* properties for Simple JWT.
*/
private final SimpleJwtProperties simpleJwtProperties;
}
@@ -17,6 +17,18 @@ import java.util.Objects;
*/
@Slf4j
public class GuidCreatorCondition implements Condition {
/**
* The condition to create bean {@code jtiCreator}.
* <p>
* If Spring does not have a bean of type
* {@link cn.org.codecrafters.guid.GuidCreator} named {@code jtiCreator}
* in the application context, then create {@code jtiCreator}.
*
* @param context the spring application context
* @param metadata the metadata of the {@link org.springframework.core.type.AnnotationMetadata class}
* or {@link org.springframework.core.type.MethodMetadata method} being checked
*/
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
final var beanFactory = Objects.requireNonNull(context.getBeanFactory());