の間で異なっている何を、私は認識インタフェースを使用してSpringのオブジェクトを取得することができます:春に認識インターフェースと@Autowired
@Component
class TestAware : ApplicationContextAware, EnvironmentAware {
override fun setEnvironment(environment: Environment) {
println("Server port" + environment.getProperty("server.port"))
}
override fun setApplicationContext(applicationContext: ApplicationContext) {
println("ApplicationContext" + applicationContext.displayName)
}
}
しかし、その後、私は@Autowiredを使用して同じことを行うことができます。
@Component
class AutowiredTest {
@Autowired
fun constructor(env: Environment, appCtx: ApplicationContext) {
println("ApplicationContext From Autowired" + appCtx.displayName)
println(env.getProperty("server.port"))
}
}
その違いは何ですか?その場合、私はAwareを使用する必要がありますが、@Autowiredは使用しないでください。