spring 属性注入时,类中必须有setter 和 getter方法。

spring配置文件里:

java业务类中注入DAO:

	private StudentDao studentDao;
// 通过属性注入
public StudentDao getStudentDao() {
return studentDao;
} public void setStudentDao(StudentDao studentDao) {
this.studentDao = studentDao;
}

 

spring 构造方法注入时,要注明属性,类中不须要setter 和 getter方法,可是须要构造器对其进行赋值。

<!-- 定义studentService的bean实例 ,并注入studentDao -->
<bean id="studentService" class="com.michael.spring.business.student.StudentServiceImpl">
<constructor-arg ref="studentDao"></constructor-arg>
</bean>

java业务类中注入DAO:

private StudentDao studentDao;

	// 通过属性注入

	public StudentDao getStudentDao() {
return studentDao;
} public void setStudentDao(StudentDao studentDao) {
this.studentDao = studentDao;
}

 

属性注入时,能够对其进行赋值,而且返回值由定义的属性值确定。

Java类中定义:

private long youknow;

	public long getYouknow() {
return youknow;
} public void setYouknow(long youknow) {
this.youknow = youknow;
}

 

<property name="youknow">
<value>245</value>
</property>

或者直接这样写:

<property name="youknow" value="245"></property>

 

 

spring 基础回想 tips01的更多相关文章

  1. Spring基础知识

    Spring基础知识 利用spring完成松耦合 接口 public interface IOutputGenerator { public void generateOutput(); } 实现类 ...

  2. spring基础整理

    spring基础教程:https://www.tutorialspoint.com/spring/spring_overview.htm 注入实例 <bean id="" c ...

  3. Spring 基础知识

    Spring架构简单描述 原文:https://www.shiyanlou.com/courses/document/212 Spring 概述 1. Spring 是什么 Spring是一个开源的轻 ...

  4. Spring基础配置

    从毕业到现在我一直从事Android开发,但是对JavaEE一直念念不忘,毕业校招的时候,一个礼拜拿了三个offer,岗位分别是Android.JavaEE和JavaSE,后来觉得Android比较简 ...

  5. Spring基础系列--AOP织入逻辑跟踪

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9619910.html 其实在之前的源码解读里面,关于织入的部分并没有说清楚,那些前置.后 ...

  6. 第65节:Java后端的学习之Spring基础

    Java后端的学习之Spring基础 如果要学习spring,那么什么是框架,spring又是什么呢?学习spring中的ioc和bean,以及aop,IOC,Bean,AOP,(配置,注解,api) ...

  7. Spring基础系列-AOP源码分析

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9560803.html 一.概述 Spring的两大特性:IOC和AOP. AOP是面向切 ...

  8. Spring基础系列-Spring事务不生效的问题与循环依赖问题

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9476550.html 一.提出问题 不知道你是否遇到过这样的情况,在ssm框架中开发we ...

  9. Spring Boot实战(1) Spring基础

    1. Spring基础配置 Spring框架本身有四大原则: 1) 使用POJO进行轻量级和最小侵入式开发 2) 通过依赖注入和基于接口编程实现松耦合 3) 通过AOP和默认习惯进行声明式编程 4) ...

随机推荐

  1. 22、Django实战第22天:课程评论

    1.编辑course-comment.html 2.编辑courses.views.py class CourseCommentView(LoginRequiredMixin, View): def ...

  2. 【2-SAT】【并查集】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem

    再来回顾一下2-SAT,把每个点拆点为是和非两个点,如果a能一定推出非b,则a->非b,其他情况同理. 然后跑强连通分量分解,保证a和非a不在同一个分量里面. 这题由于你建完图发现都是双向边,所 ...

  3. 【数位dp】hdu3555 Bomb

    题意就是找0到n有多少个数中含有49.数据范围接近10^20 DP的状态是2维的dp[len][3]dp[len][0] 代表长度为len不含49的方案数dp[len][1] 代表长度为len不含49 ...

  4. 【博弈论】poj2484 A Funny Game

    如果当前状态可以根据某条轴线把硬币分成两个相同的组,则当前状态是必败态. 因为不论在其中一组我们采取任何策略,对方都可以采取相同的策略,如此循环,对方必然抽走最后一枚硬币. 因为我们先手,因此抽完后盘 ...

  5. 【最大流】【费用流】bzoj1834 [ZJOI2010]network 网络扩容

    引用题解: 最大流+费用流. 第一问最大流即可. 第二问为“最小费用最大流”. 由题意,这一问的可转化为在上一问的“残量网络”上,扩大一些边的容量,使能从新的图中的最大流为k. 那么易得:对于还有剩余 ...

  6. Oracle常见故障问题

    1. ORA-27102: out of memory 创建pfile文件: create pfile from spfile: 修改pfile文件 修改文件/home/oracle/app/orac ...

  7. svn的安装(整合apache、ldap)包括错误解决post commit FS processing had error

    2013年12月5日 admin 发表评论 阅读评论 以下是centos环境下,以yum安装apache及其相关软件.svn使用源码包编译,使用官网最新的1.8.5版本. 一.安装apache ope ...

  8. Swift,闭包

    闭包(相当于匿名函数)的几种情况 利用sorted()排序方法来进行示例 1.sorted()正常引用的情况 var str=["d","a","c& ...

  9. pandas判断缺失值的办法

    参考这篇文章: https://blog.csdn.net/u012387178/article/details/52571725 python pandas判断缺失值一般采用 isnull(),然而 ...

  10. 精通JavaScript攻击框架:AttackAPI

    多年来客户端安全一直未引起人们的足够重视,但是如今情况发生了急剧转变,客户端安全已经成为信息安全领域的焦点之一.Web恶意软件.AJAX蠕虫.浏览历史暴破.登录检测.傀儡控制技术网络端口扫描以及浏览器 ...