当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 0

OuSheobin / Spring-IOC-Homework
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

#Spring-IOC-Homework

这是王芳老师的Spring框架实现控制反转和依赖注入作业的样例

##使用的开发与测试环境##

  • 使用Eclipse Neon2 开发,普通Java项目
  • 数据库使用 MySQL 5.6,需要更换数据库的,请修改config/beans.xml
  • 默认数据表 crm_lite 默认字符编码 UTF-8 Bin
  • 默认日志框架 Log4j 日志级别为INFO

程序入口:cn.oushaobin.spring.demo.MainEntrance

数据库相关

如果第一次运行,需要在目标数据库执行下列建表语句(MySQL5.6+InnoDB)

	DROP TABLE IF EXISTS `tb_user`;
	CREATE TABLE `tb_user` (
		`f_id` int(11) NOT NULL AUTO_INCREMENT,
  		`f_address` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  		`f_birthday` datetime DEFAULT NULL,
  		`f_email` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  		`f_password` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  		`f_username` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  		PRIMARY KEY (`f_id`)
	) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

关于Spring IOC控制的说明

本作业里面使用了两种注入方式

一种是使用静态BeanFactory调用getBean()获取,例如

SpringBeanFactory.getBean("customerDao");

还有一种是使用注解@Autowired的方法注入,首先在beans.xml配置扫描路径

<context:component-scan base-package="cn.oushaobin.spring.dao.*"/>

然后再目标类加上@Service,@Component,@Repository等注解,声明为组件,例如:

@Repository(value = "customerDao")
public class CustomerDaoImpl implements CustomerDao {

  @Autowired(required = true)
  JdbcTemplate jdbcTemplate;
  ...

}

这时候,Spring会自动把CustomerDaoImpl作为一个Bean,并且完成对jdbcTemplate的自动注入

The MIT License (MIT) Copyright (c) 2017 OuSheobin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

王芳老师的Spring IOC作业 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/ousheobun/spring-ioc-homework.git
git@gitee.com:ousheobun/spring-ioc-homework.git
ousheobun
spring-ioc-homework
Spring-IOC-Homework
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891