#spring bean加载 ,定义变量 没有@component也能生效

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

public class MyComponent {

    @Value("${my.property}")
    private String myProperty;

    // Getter and Setter
}

@Service
public class MyService {

    private final MyComponent myComponent;

    @Autowired
    public MyService(MyComponent myComponent) {
        this.myComponent = myComponent;
    }
}

//====================================
public class MyComponent {
    @Value("${my.property}")
    private String myProperty;

    // Getter and Setter
}

@Configuration
public class AppConfig {
    @Bean
    public MyComponent myComponent() {
        return new MyComponent();
    }
}