本博客依据是是spring原始注解-02的代码


注入普通数据类型:@Value注解的使用
1.添加driver属性,使用value注解

@Service("userService")
public class UserServiceImpl implements UserService {@Value("${jdbc.driver}")private String driver;@Autowired//@Qualifier("userDao") //要注入的id值private UserDao userDao;@Overridepublic void sava() {System.out.println(driver);userDao.save1();}
}

2.applicationContext.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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!--    配置组件扫描-->
<!--    spring会扫描hao包下的所有子包和该包下的所有类--><context:component-scan base-package="com.hao"/><!--    加载外部的properties配置文件--><context:property-placeholder location="classpath:jdbc.properties"/>
</beans>

3.测试

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

结果:
com.mysql.cj.jdbc.Driver
save running…


这个是演示Scope注解的使用,如果不懂Scope的作用请访问scope的作用


这里演示的是@PostConstruct注解和@PreDestory注解相当于init-method和destory-method方法,不了解可以访问init-method和destory-method方法

注意:销毁方法中不会被打印出来信息,因为spring容器还没有关闭,Java代码已经执行结束

spring原始注解(value)-03相关推荐

  1. spring原始注解开发-01

    我们使用xml-Bean标签的配置方式和注解做对比理解 1.创建UserDao接口以及UserDao的实现类UserDaoImpl(接口代码省略) public class UserDaoImpl i ...

  2. spring原始注解

    spring原始注解主要是替代Bean标签的配置 @Component:使用在类上用于实例化Bean @Controller:使用在web层类上用于实例化Bean @Service:使用在servic ...

  3. Spring原始注解和新注解(使用注解代替xml配置文件)

    Spring原始注解 spring的原始注解主要是为了替代xml文件中配置的 < bean > @Component:使用在类上用于实例化Bean @Controller:使用在web层类 ...

  4. Spring原始注解开发-02

    使用@Repository.@Service.@Controller注解配置,使其更加清晰属于哪一层,因为我是模拟的web层,所有没有使用@Controller注解,后面结合web开发会使用到 1.创 ...

  5. Spring之注解开发

    8.使用注解开发 8.1.什么是注解? 注解是代码特殊标记,格式:@注解名称(属性名称=属性值,属性名称=属性值) 使用注解,注解作用在类上面,方法上面,属性上面 使用注解目的:简化xml文件的配置. ...

  6. Spring系列之Spring常用注解总结

    参看博客:https://www.cnblogs.com/xiaoxi/p/5935009.html 传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺 ...

  7. Spring常用注解总结

    传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点: 1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文 ...

  8. spring autowired idea都匹配上了_你清楚这几个Spring常用注解吗?

    作者:平凡希http://cnblogs.com/xiaoxi/p/5935009.html 传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点: 如 ...

  9. Spring中注解大全

    Spring中注解大全 @Controller 标识一个该类是Spring MVC controller 处理器,用来创建处理http请求的对象 @Controller public class Te ...

最新文章

  1. 数据库更行通知_哪个更好? 数据驱动还是数据通知?
  2. kohana task 编写计划任务
  3. 1加6投屏_今天说说投屏那点事,建议大家选购投屏器,要关注这些点
  4. java中的exception stack有时候不输出的原因
  5. A - TOYS POJ - 2318
  6. 【英语学习】【WOTD】gibbous 释义/词源/示例
  7. iPhone 5的发布日期估计为9月21日挂
  8. 机器学习之路: python 决策树分类DecisionTreeClassifier 预测泰坦尼克号乘客是否幸存...
  9. java struts2 验证码,struts2中验证码的生成和使用
  10. 谷歌卫星地图下载器与万能地图下载器功能比较
  11. WIFI和路由器密码破解的方法
  12. 听力1-10中的不熟悉的单词
  13. ept技术_EPT和VPID简介 - osc_3xz91vxi的个人空间 - OSCHINA - 中文开源技术交流社区
  14. vue仿美团饿了么--底部导航公共组件
  15. PHP/Golang实现—数据结构之顺序栈
  16. JS 遍历对象 jQuery遍历对象
  17. raspberry pi_如何制作Raspberry Pi游戏手柄
  18. 在uniapp中怎么实现邀请好友
  19. Vuepress2版本打包报错:TypeError: Invalid value used as weak map key
  20. 计算机工程科学怎么翻译,汉英机器翻译中汉语篇章时间信息系统模型 - 计算机工程与科学.pdf...

热门文章

  1. BZOJ3577 : 玩手机
  2. C#、.Net经典面试题目及答案
  3. ora-24811提供写入的数据少于指定的数据_C++开源、高性能时序数据库pinusdb
  4. 数据包格式_理解MQTT协议数据包结构
  5. hive explode
  6. centos7 php 404,CentOS7 Apache环境配置自定义404错误页面怎么解决
  7. 三十九、Java集合中的HashSet和TreeSet
  8. 四十八、使用Python和Stata完成广西碳酸钙企业的主成分分析和因子分析
  9. 三十九、Scrapy-redis框架分布式部署
  10. 五、Requests库详细的用法