Get a proxy instance of the component itself in Spring Boot

Premise

From a component with RequestScope etc., I had to return a class that holds the proxy (because it is checked for equivalence where I can't touch it).

Solution

I don't know if this was good, but I was able to realize myself by ʻAutowired`.

@Component
@RequestScope
public class Hoge {
  private final Hoge proxyInstance;
  @AutoWired
  public(Hoge proxyInstance) {
    if (!(proxyInstance instanceof ScopedObject)) {
      throw new IllegalArgumentException("Pass the proxy");
    }
    this.proxyInstance = proxyInstance;
  }

  public Fuga getFuga() {
    return new Fuga(proxyInstance);
  }
}

Recommended Posts

Get a proxy instance of the component itself in Spring Boot
Get the path defined in Controller class of Spring boot as a list
Specify the encoding of static resources in Spring Boot
A story packed with the basics of Spring Boot (solved)
Get the public URL of a private Flickr file in Java
Get a list of other sessions of the same user when using Redis Session in Spring Boot (2 series). Also discard it.
Get the result of POST in Java
Procedure to make the value of the property file visible in Spring Boot
How to get the absolute path of a directory running in Java
Measure the size of a folder in Java
The story of raising Spring Boot 1.5 series to 2.1 series
Let's check the feel of Spring Boot + Swagger 2.0
How to add a classpath in Spring Boot
Java tips-Create a Spring Boot project in Gradle
View the Gradle task in the Spring Boot project
Introducing the Spring Boot Actuator, a function that makes the operation of Spring Boot applications easier.
How to get the ID of a user authenticated with Firebase in Swift
Organize the differences in behavior of @NotBlank, @NotEmpty, @NotNull with Spring Boot + Thymeleaf
Sign in to a Spring Boot web application on the Microsoft ID platform
[Spring Boot] How to get properties dynamically from a string contained in a URL
Get the class name and method name of Controller executed by HandlerInterceptor of Spring Boot
How to set environment variables in the properties file of Spring boot application
Get multiple Resources that match the pattern in spring
Get the URL of the HTTP redirect destination in Java
Count the number of occurrences of a string in Ruby
Format of the log output by Tomcat itself in Tomcat 8
I checked asynchronous execution of queries in Spring Boot 1.5.9
[For beginners] DI ~ The basics of DI and DI in Spring ~
I want to get the information of the class that inherits the UserDetails class of the user who is logged in with Spring Boot.
A memorandum of addiction to Spring Boot2 x Doma2
Get the name of the test case in the JUnit test class
Access the built-in h2db of spring boot with jdbcTemplate
05. I tried to stub the source of Spring Boot
How to create a Spring Boot project in IntelliJ
The story of making a reverse proxy with ProxyServlet
I tried to reduce the capacity of Spring Boot
Get a list of classes in a Guava specific package
[Java] Get the file in the jar regardless of the environment
How to use CommandLineRunner in Spring Batch of Spring Boot
A review note of the Spring Framework Resource interface
Get the URL of the HTTP redirect destination in Ruby
Specify spring.profiles.active via context-param of web.xml in Spring Boot
Check the behavior of getOne, findById, and query methods in Spring Boot + Spring Data JPA
Get cookies in Spring
A record of studying the Spring Framework from scratch
[Ruby] Get in the habit of using the dup method when making a copy of a string variable
Branch processing by the return value of RestTemplate and the status code of ResponseEntity in Spring Boot
Spring Boot 1.x will reach EOL in the next year.
The story of raising Spring Boot from 1.5 series to 2.1 series part2
About the function of Spring Boot due to different versions
Check the dependency of a specific maven artifact in Coursier
Get the object name of the instance created by the new operator
Put the file in the properties of string in spring xml configuration
Determine that the value is a multiple of 〇 in Ruby
Accelerate testing of Validators that require DI in Spring Boot
Get error information using DefaultErrorAttributes and ErrorAttributeOptions in Spring Boot 2.3
A program that counts the number of words in a List
[jsoup] How to get the full amount of a document
Find the number of days in a month with Kotlin
Get started with Spring boot
Spring Boot 2 multi-project in Gradle