Java预备、起飞

终于有大佬把软件测试的元素定位总结得这么通俗易懂了!

  返回  

spring注解入门

2021/7/21 18:47:33 浏览:

在这里插入图片描述

@Component("userDao")
public class UserDaoImpl implements UserDao {

    @Override
    public void save() {
        System.out.println("lovelive");
    }
}

//   <bean id="userService" class="com.ruan.test.ruan.servire.impl.UserServiceImpl" >
@Component("userService")
public class UserServiceImpl implements UserService {
    //        <property name="userDao" ref="userDao"></property>
    @Autowired
    @Qualifier("userDao")
    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public void save() {

        userDao.save();
    }
}

xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:context="http://www.springframework.org/schema/context"
               xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
">


<!--配置主键扫描-->
    <context:component-scan base-package="com.ruan"/>
</beans>

测试

public class UserController {
    public static void main(String[] args) {
        ApplicationContext app=new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = app.getBean(UserService.class);
        userService.save();
    }
}

在这里插入图片描述

联系我们

如果您对我们的服务有兴趣,请及时和我们联系!

服务热线:18288888888
座机:18288888888
传真:
邮箱:888888@qq.com
地址:郑州市文化路红专路93号