Skip to content

luversof/bluesky-boot-autoconfigure-devcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bluesky-boot-autoconfigure-devcheck

bluesky-boot-autoconfigure-devcheck is a library that helps you check the list of controller methods for developer checks and the list of commonly used utility static methods that Spring Boot-based projects create to check their development.

The list of controller methods for development checks can be found in /_check and the list of utility static methods can be found in /_check/util.

If you are using Thymeleaf, the list is provided based on the Thymeleaf UI, otherwise the list is provided in JSON.

Prerequisites

settings

maven dependencies

<dependencies>
    <dependency>
        <groupId>io.github.luversof</groupId>
        <artifactId>bluesky-boot-autoconfigure-devcheck</artifactId>
        <version>3.1.0</version>
    </dependency>
</dependencies>

properties

This library is enabled by default when you add it to a dependency.

If you want to disable the functionality of this library in your live service environment, set it up as follows

bluesky-boot.dev-check.enabled=false

Searches for utility static methods in the specified scope.

Specify the packages to be scanned as follows:

bluesky-boot.dev-check.base-packages=net.luversof

If you want to change the default address for devCheck, set it as follows.

The default value is /_check.

bluesky-boot.dev-check.path-prefix=/info/_check

You can also set it to a path pattern.

bluesky-boot.dev-check.path-prefix=/{somePath}/_check

usage

DevCheckDescription annotation

Use the DevCheckDescription annotation to represent a description of the method on the /_check page.

It can be used for controller methods and utility static methods.

attribute description
value Description added under method
displayable Whether the list is exposed

controller method

The controller bean is the target of the /_check page listing that satisfies the following conditions.

  • Declare the @DevCheckController annotation
  • The produce attribute is set to application/json
  • Set the path to start with ${bluesky-boot.dev-check.path-prefix}.

Create a controller like this:

@DevCheckController
@RestController
@RequestMapping(value = "${bluesky-boot.dev-check.path-prefix}/core",  produces = MediaType.APPLICATION_JSON_VALUE)
public class DevCheckCoreController {

	private ApplicationContext applicationContext;

	public DevCheckCoreController(ApplicationContext applicationContext) {
		this.applicationContext = applicationContext;
	}

	@DevCheckDescription("spring activeProfiles")
	@GetMapping("/activeProfiles")
	public String[] activeProfiles() {
		return applicationContext.getEnvironment().getActiveProfiles();
	}
	
	// create GetMapping method you want to check
}

The getMapping method of that controller is added to the /_check list, as shown below.

_check

utility static method

Declare the @DevCheckUtil or @ReactiveDevCheckUtil annotation on the utility class you want to add to the /_check/util list.

Use it like this:

@DevCheckUtil
public class UserUtil extends RequestAttributeUtil {
	
	@Setter(onMethod_ = @DevCheckDescription(displayable = false))
	private static LoginUserService loginUserService;
	
	private static final String LOGIN_USER = "__loginUser";

	@DevCheckDescription("get loginUser")
	public static Optional<User> getLoginUser() {
		Optional<User> userOptional = getRequestAttribute(LOGIN_USER);
		if (userOptional != null) {
			return userOptional;
		}
		
		userOptional = loginUserService.getUser();
		setRequestAttribute(LOGIN_USER, userOptional);
		
		return userOptional;
	}
}

The corresponding utility static method is added to the /_check/util list, as shown below.

_check

version history

version prerequisites
1.0.1 Java 11, Spring Boot 2.5.4
1.0.2 Java 11, Spring Boot 2.6.1
2.0.0 Java 17, Spring Boot 2.7.1
3.1.0 Java 17, Spring Boot 3.1.0