Annotation-based ioc for spring learning

@component
creates the same object as the bean tag of the xml configuration
@autowrite is
used to inject data and the property of the bean tag is the same
@Qualifier
obtains the bean object according to the component id

@Autowired
@Qualifier("userMapper")
private UserMapper userMapper;

@Resoure
is a combination of the first two

@Resource(name = "userMapper")
private UserMapper userMapper;

Injected bean

@Component("userService")
public class UserServiceImpl implements UserService {
    
    


    @Autowired
    private UserMapper userMapper;


    @Override
    public void findById() {
    
    
        userMapper.findById();
    }
}

Inject string
@value

@Value(value = "adb")
private String str;

@Scope is
used to change the scope of action. The
default is singleton

There is also bean life cycle annotation
@PreDestory destroying
@PostConstrast initialization

Guess you like

Origin blog.csdn.net/qq_42794826/article/details/114606936