关于ssh三大框架整合的碎碎念
三大框架整合,无非就是一个导jar包,修改配置文件的过程。完了就没事了。
还是有很多细节性的问题
比如在spring中写applicationContext.xml文件时不提示:
解决方法如下:
如果写xml不提示:
Window-preferences-myeclipse-xml-xml catalog-user specified entries-add-
1. location:spring-beans-3.1.xsd的路径,在D:\学习\Java\spring\spring-framework-3.2.1.RELEASE-dist\spring-framework-3.2.1.RELEASE\schema\beans(这是我的路径,写上自己的路径即可)
2. uri 路径,同上
3. key type:Schema Location
4. key: http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
xml文件在xmlcatalog中找与key中字符串相同的文件即spring-beans-3.1.xsd
.xsd文件,指明了被这个文件指明的xml文件中能写什么不能写什么
项目中的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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
Spring对Dao层的支持:
Spring提供了Dao框架,让开发人员无须耦合特定的数据库技术就能进行应用程序的开发
通过DAO接口进行开发,接口的实现通过spring注入
如:User user = new User();
//通过spring配置文件获得UserDao实现类
UserDao userdao=getUserDao();//getUserDao()就是context.getBean();
//再调用dao层的方法
Userdao.insert(user);
getUserDao()就是context.getBean();因此,由于依赖于接口,可以通过依赖注入随时替换UserDao接口的实现类,而应用程序完全不用了解接口和底层数据库的操作细节。
Spring使用持久层,必须知道数据源在哪里,所以要注入数据源。用注入数据源的方式注入数据库。连接数据的方式称为“数据源”,比如JDBC,连接池或者JNDI
Spring通过依赖注入的方式配置数据源:不同系统,数据源的管理更多是针对底层的行为,这些行为不应该影响业务。更换数据源只需要修改bean定义的内容,而不需要修改任何一行代码。
配置datasource
在配置文件中配置数据源:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSouerce">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@localhost:1521:ORCL</value>
</property>
<property name="username">
<value>scott</value>
</property>
<property name="password">
<value>admin</value>
</property>
</bean>
配置PersonDaoBean:datasource所要注入的对象
<bean id="personDao" class="spring.jdbc.dao">
<property name="dataSource" ref="dataSource"/>
</bean>
通过ref属性,spring启动时,dataSource属性就注入到PersonDaoImpl中了。
过程:根据ref中的dataSource去查找persondaoImpl中的setdataSource方法,
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
上面的数据源配置通过参数dataSource传入persondaoImpl的成员变量里。
关于ssh三大框架整合的碎碎念的更多相关文章
- Maven SSH三大框架整合的加载流程
<Maven精品教程视频\day02视频\03ssh配置文件加载过程.avi;> 此课程中讲 SSH三大框架整合的加载流程,还可以,初步接触的朋友可以听一听. < \day02视频\ ...
- SSH三大框架整合案例
SSH三大框架的整合 SSH三个框架的知识点 一.Hibernate框架 1. Hibernate的核心配置文件 1.1 数据库信息.连接池配置 1.2 Hibernate信息 1.3 映射配置 ...
- JavaWeb_(SSH)三大框架整合struts+hibernate+spring_Demo
三大框架整合 一.SSH导包 二.书写Spring 三.书写Struts 四.整合Spring与Struts 五.书写(与整合)Hibernate.引入c3p0连接池并使用hibernate模板 六. ...
- SSH三大框架整合配置详解
首先,三大框架整合,肯定是要导入相当多的jar包,这是不容置疑的! 这里就不一一列举了,直接截图吧: (1) 基于配置文件的整合: 第一步:我们需要在we ...
- SSH 三大框架整合
Spring整合web项目 在Servlet当中直接加载配置文件,获取对象 存在问题 每次请求都会创建一个Spring的工厂,这样浪费服务器资源,应该一个项目只有一个Spring的工厂. 在服务器启动 ...
- SSH三大框架整合步骤
Struts2:需要整合的第一个框架: 1.创建一个动态web项目 2.导入struts2必须的jar 放到 lib目录下 ,再 build path 添加web工程中 3.配置struts2的核心配 ...
- JAVAEE——SSH三大框架整合(spring+struts2+hibernate)
一.整合原理 二.导包(41个) 1.hibernate (1)hibernate/lib/required (2)hibernate/lib/jpa | java persist api java的 ...
- SSH三大框架整合配置详细步骤(3)
5 配置Spring2.5 5.1 基础配置 1) 导入spring包.下载spring-framework-2.5.6并解压后,在spring-framework-2.5.6" ...
- SSH三大框架整合使用的配置文件 注解实现
1 Struts.xml 使用拦截器 <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE str ...
随机推荐
- Node js路由
/* 要为程序提供请求的 URL 和其他需要的 GET 及 POST 参数,随后程序需要根据这些数据来执行相应的代码. 因此,需要查看 HTTP 请求,从中提取出请求的 URL 以及 GET/POST ...
- 代码编写规范Asp.Net(c#)
1 目的 为了统一公司软件开发的设计过程中关于代码编写时的编写规范和具体开发工作时的编程规范,保证代码的一致性,便于交流和维护,特制定此规范. 2 范围 本规范适用于开发组 ...
- [洛谷P3224][HNOI2012]永无乡
题目大意:给你$n$个点,每个点有权值$k$,现有两种操作: 1. $B\;x\;y:$将$x,y$所在联通块合并2. $Q\;x\;k:$查询第$x$个点所在联通块权值第$k$小是哪个数 题解:线段 ...
- bzoj 1221: [HNOI2001] 软件开发 (网络流)
注意说如果直接从每天的新的连向旧的,那整个图的最大流还是不变,答案就一直会是Σni*f type arr=record toward,next,cap,cost:longint; end; const ...
- 122. Best Time to Buy and Sell Stock II (Array)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- 三个月死磕Python是种什么样的体验?
3个月的死磕Python后,参加「 楼+ Python实战 · 第4期 」的学员们感想如何?下面带来他们的真实评价. 作为实验楼的网红课程——「 楼+ Python实战 」已经走过了第四期,经过了三个 ...
- C#基础-连接Access与SQL Server
1.连接Access数据库 string strConnection = "Provider=Microsoft.Ace.OleDb.12.0; Data Source=" + S ...
- BZOJ3571 & 洛谷3236:[HNOI2014]画框——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=3571 https://www.luogu.org/problemnew/show/P3236 小T ...
- BZOJ1086:[SCOI2005]王室联邦——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1086 题面源于洛谷. 题目描述 “余”人国的国王想重新编制他的国家.他想把他的国家划分成若干个省,每 ...
- JavaScript关键字return的用法
return 语句从当前函数退出,并从那个函数返回一个值. 语法: 1 return[()[expression][]]; 可选项 expression 参数是要从函数返回的值.如果省略,则该函数不返 ...