java technical details


Java details technical point


class name.this, which is generally used for inner classes to call outer classes. What is the function of ordinary methods annotated


with @Autowired?
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user").password("password").roles("USER");
    }
}

Spring will instantiate all beans first, and then scan according to the configuration. When @Autowired is detected, it will be injected, and this method will be called during injection.
In fact, this annotation gets to the property, and you will understand that this is dependency injection. The way to get the method is to inject the method parameter type when instantiating the class.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326517498&siteId=291194637
Recommended