[Java] JavaConfig with Static InnerClass

The beginning is lazy

With a little operation check, I want to register only the components I want to use in the DI container while avoiding that ComponentScan scans all the components under the package of my class, but the" Bean definition file "and" New JavaConfig " Creating a "class" became ** troublesome **, and when I wrote it in the class I wanted to check the operation with momentum, it worked.

StaticNaInnnerClassDeJavaConfig.java


@SpringBootApplication(scanBasePackages = { "undefined.package" })
@Component
public class StaticNaInnnerClassDeJavaConfig {

    private final SomeComponent component;

    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(StaticNaInnnerClassDeJavaConfig.class, args);
    }

    public StaticNaInnnerClassDeJavaConfig(SomeComponent component) {
        this.component = component;
    }

    public static class JavaConfig {
        @Bean
        public SomeComponent someComponent(@Autowired Properties properties) {
            return new SomeComponent(properties);
        }
    }

    public static class SomeComponent {
        private final String someParam;
        public SomeComponent(Properties proeprties) {
            this.someParam = properties.getProperty("someParam");
        }
    }

}

Recommended Posts

[Java] JavaConfig with Static InnerClass
Java static
Static code analysis with Checkstyle in Java + Gradle
Install java with Homebrew
Change seats with java
Comfortable download with JAVA
Switch java with direnv
Java static [Personal summary]
Download Java with Ansible
Let's scrape with Java! !!
Build Java with Wercker
Endian conversion with JAVA
Include image in jar file with java static method
Easy BDD with (Java) Spectrum?
Use Lambda Layers with Java
Java multi-project creation with Gradle
Getting Started with Java Collection
Java Config with Spring MVC
Basic Authentication with Java 11 HttpClient
Let's experiment with Java inlining
Run batch with docker-compose with Java batch
Rewrite Java try-catch with Optional
Install Java 7 with Homebrew (cask)
Java to play with Function
Try DB connection with Java
Mock static methods with PowerMock
[Java] Stack area and static area
Enable Java EE with NetBeans 9
Try gRPC with Java, Maven
Let's operate Excel with Java! !!
Version control Java with SDKMAN
Enhanced Java compilation errors with the static analysis tool ErrorProne
RSA encryption / decryption with java 8
Paging PDF with Java + PDFBox.jar
Sort strings functionally with java
Object-oriented (java) with Strike Gundam
[Java] Content acquisition with HttpCliient
Java version control with jenv
Troubleshooting with Java Flight Recorder
Streamline Java testing with Spock
Connect to DB with Java
Connect to MySQL 8 with Java
[java] Reasons to use static
Error when playing with java
Using Mapper with Java (Spring)
Java study memo 2 with Progate
[Java] Classes, constructors, static members
Getting Started with Java Basics
Seasonal display with Java switch
Use SpatiaLite with Java / JDBC
Benefits of Java static method
Study Java with Progate Note 1
Compare Java 8 Optional with Swift
HTML parsing with JAVA (scraping)
Run Java VM with WebAssembly
Screen transition with swing, java
Java unit tests with Mockito
[Java 8] Duplicate deletion (& duplicate check) with Stream
Create an immutable class with JAVA
Java lambda expressions learned with Comparator
About Java static and non-static methods