Spring学习笔记

IoC -- beans.xml /applicationCntext.xml

容器
1.BeanFactory -- XmlBeanFactory
org.springframework.beans.factory.BeanFactory
加载Bean 延迟载入 -- getBean() 方法

2.ApplicationContext -- ClassPathXmlApplicationContext
org.springframework.context.ApplicationContext
预载入单实例

注入三种方式,常用的是构造函数注入和setter方法注入,如下

public class Course{
//关联声明
private Student st
private Teacher tr

public Course(){
}

//构造函数注入
public Course(Teacher atr){
this.tr = atr; //使用标签
}

//setter 方法注入
public void setStudent(Student ast){
this.st = ast; //使用标签
}
}

关于sessionFactory -- 一般用于配置Hibernate 链接池

第一步: 在spring文件中配置如下:


//这个就是Hibernate的勾子

classpath:hibernate.cfg.xml



第二步:配置hibernate.cfg.xml文件:

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"https://www.360docs.net/doc/b017060011.html,/hibernate-configuration-3.0.dtd">



jdbc:mysql://localhost/spring_hibernate_2
com.mysql.jdbc.Driver
root
root
org.hibernate.dialect.MySQLDialect
true
thread






init-method/destroy-method

BeanPostProcessor 有两个方法,在context中注册,对每个bean都起作用

BeanFactoryPostProcessor -- 操作BeanFactory

ApplicationListener -- onApplicationEvent 监听事件 ApplicationContext
ApplicationEvent -- ApplictionContext.publishEvent() 发布事件

-------------------------------------------------------------------------
Aop

aspect(切面) -- Advisor(pointcut and advice)
joinpoint(连接点) -- 属性连接点
Advice(通知) -- 方法拦截
pointcut(切入点) --
Target
Proxy
Weaving

https://www.360docs.net/doc/b017060011.html,ng.reflect.Proxy 有暴露接口 -- 接口创建代理
2.CGLIB 无暴露接口 -- 类创建代理 --final 方法不能被通知

Around 拦截对目标方法的调用 org.aopalliance.intercept.MethodIntercept

or
Before org.springframework.aop.BeforeAdvice
Afer org.springframework.aop.AferReturningAdvice
Throwa org.springframework.aop.ThrowAdvice

public interface MethodBeforeAdvice{} 抛出异常
public interface AfterReturningAdvice()
public interface MethodInterceptor extends Interceptor

MethodInvocation.proceed();

ThrowsAdvice{}

afterThrowing
---------------------------------------
pointcut
1.CalssFilter 类是否符合
2.MethodMatcher 方法是否符合

静态,动态
-----------------------------
PointcutAdvisor{} -- NameMatchPointcut
setMappedName
setMappedNames

-- RegexpMethodPointcut

IntroductionInterceptor -- IntroductionMethodInterceptor
MethodInterceptor.Invoke()
DelegatingIntroductionInrceptor
IntroductionAdvisor
DefaultIntroductionAdvisor

BeanNameAutoProxyCreator 自动代理 相同命名规则

Spring DAO

DataAccessException -- RuntimeException,NestedRuntimeException(getCause)
DataRetrivevalFailureException
DataAccessRecourceFailureException

JNDI


java:comp/env/jdbc/myDatasource




1.Prepare Resources
2.Stamt Transaction -- 3.Execute in transaction
4.Return Data
https://www.360docs.net/doc/b017060011.html,mit/Rollback --
Transaction
6.Close Resources and Handle Errors

JdbcTemplate template = new JdbcTemplate(dataSource) //可用配置注入
template.update(sql,params[],types[]);

RowMapper(mapRow)
RowMapperResultReader

template.query(sql,params,new RowMapperResultReader(new RowMapper()))

transaction manage

1.jdbc,Hibernate
DataSourceTransactionManager 单一jdbc datasource
HibernateTransactionManager Hibernate 数据源
JdoTransactionManager
2.JTA
JtaTransactionManager

编码式事务

transactionTemplate.execute(
new TransactionCallback(){
public Object doInTransaction(TransactionStatus ts){

}
}
);

----------------------------------------------
声明式事务

TransactionProxyFactoryBean --2.0 之前的版本











PROPAGATION_REQUIRED










事务属性
1.传播行为 propagation_mandatory 一定要事务
2.隔离级别 isolation_read_uncommitted
3.自读 readonly
4. -Exception 抛出异常,回滚
5. +Exception 抛出异常,仍提交

通过方法名声明事务

NameMatchTransactionAttributeSource

用元数据声明
AttributesTransactionAttributeSource
详细看看

2.0开始后的方式,更加简洁--perfect


















话说增加了OSGI的实现

Spring Autowire自动装配 autowire=""

远程调用:

1.RMI RmiProxyFactoryBean java.rmi.Remote java.rmi.RemoteException
2.Http HttpInvokerProxyFactoryBean,HttpInvokerServiceExporter
3.Hessian HessianProxyFactoryBean,HessianServiceExporter
4.Burlap BurlapProxyFactoryBean BurlapServiceExporter(xml)

------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
Struts -- struts.xml

HttpServletReqeust -- ActionMapper -- FilterDispatcher -- Other filter(SiteMesh,etc) -- ActionContextClearup

-- ActionProxy -- ActionInvocation -- Interceptor1,2,3 -- Action -- Result -- Template(JSP,Velocity) -- Interceptor 3,2,1
Configuration Manager(struts.xml)

-- HttpServletResponse


ActionServlet -- ActionForm.validate() -- ActionMapping -- Action.execute() -- ActionForward
















execute(Struts) -- processAction(Portal)
doGet
doPost
doView...................

---------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------

---------------------------------------------------
Hibernate -- xxx.hbm.xml
ORM
Persistent(Javabean POJO) -- session
Transaction(org.hibernate.Transaction)

Interface
1.Session -- 非线程安全
2.SessionFactory -- 对应数据库
3.Configuration --2012-8-18
4.Transaction --
5.Query
6.Criterial

主键生成方式
1.Assign
2.Hilo
hibernate_unique_key,默认字段叫作next_hi。next_hi必须有一条记录否则会出现错误。
3.Incrementt
4.Identity
5.Sequence
6.Native
7.UUID
8.Foreign GUID

一级缓存 -- Session级别的缓存
二级缓存 -- SessionFactory级别(查询缓存)
-- EhCache
-- OSCache
-- JBossCache

Hibernate的二级缓存策略,是针对于ID查询的缓存策略,对于条件查询则毫无作用。为此,Hibernate提供了针对条件查询的Query Cache。

lazy loading 延迟加载

这种初始化策略只在一个对象调用它的一对多或多对多关系时才将关系对象读取出来。
缺陷:Hibernate会话一直开着,为了及时读取数据,破坏DAO.
Spring OpenSessionInViewFilter -- 前加载 -- org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
OpenSessionInViewInterceptor -- 后加载,Spring容器 --

事务隔离级别
ISOLATION_DEFAULT
更新丢失(Lost update) -- 未授权读取 ISOLATION_READ_UNCOMMITTED
脏读,会覆盖前面的数据 -- 授权读取 ISOLATION_READ_COMMITTED
重复读取 -- 可重复读取 ISOLATION_REPEATABLE_READ
-- 序列化 ISOLATION_SERIALIZABLE

批量操作 -- BATCH bulk delete/update

dynamic-insert default value:false
dynamic-update default value:false
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
JavaMail

接受pop3

Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props, null);

Store store = session.getStore("pop3");
store.connect("https://www.360docs.net/doc/b017060011.html,", "chenyifa0103", "chenyifa0103");

Folder folder = store.getDefaultFolder();
Folder inbox = folder.getFolder("INBOX");

inbox.open(FOLDER.READ_ONLY);
Message[] msgs = folder.getMessages();
.......
.......
.......




发送smtp -- javax.mail.Authenticator(user_login) Mime 格式
SMTP_HOST_NAME
SMTP_AUTH_USER
SMTP_AUTH_PWD
emailMsgTxt
emailSubjectTxt

Properties props = System.getProperties();
props.put("mail.smtp.host","stmp:");
props.put("mail.smtp.auth",true);

Authenticator = new Authenticator();

Session session = Session.getDefaultInstance(props,authenticator);


MimeMessage msg = new MimeMessage(session);

msg.setFrom("XXXXX");
msg.setRecipients("XXXXXX");
msg.setSubject("XXXXXXX");


Multipart mp = new MimeMultipart(); //邮件内容,包括所有

MimeBodyPart mbpContent

= new MimeBodyPart(); //邮件主体
MimeBodyPart mbpFile = new MimeBodyPart(); //邮件附件

mbpContent.setText(content); //主文

FileDataSource fds = new FileDataSource(filename); //附件文件路径
mbpFile.setDataHandler(new DataHandler(fds)); //附件文件操作处理器
mbpFile.setFileName(fds.getName()); //读取附件文件


mp.addBodyPart(mbpContent); //加载主文
mp.addBodyPart(mbpFile); //加载附件

msg.setContent(mp);
msg.setSendDate(new Date());

Transport.send(msg);


------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
JAXB(Java Architecture for XML Bing) -- 我用的是SAX
XML Schema --> Javabean
javax.xml.bind.annotation --
JAXBContext --> Marshallers(Java-->XML)/Unmarshallers(XML-->Java)
xsd:string --> https://www.360docs.net/doc/b017060011.html,ng.String 以此类推其它数据类型映射

JAXBContext jc = JAXBContext.newInstance("https://www.360docs.net/doc/b017060011.html,erinfo");
ObjectFactory objFactory = new ObjectFactory(); //生成对象工厂

------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
PL/SQL

右连接的写法(右)
Select a.studentno,a.studentname,b.classname
From students a,class b
Where a.classid(+)=b.classid; //以右表为主,左为空补空

左连接
Select a.studentno,a.studentname,b.classname
From students a,class b
Where a.classid=b.classid(+); //以左表为主,右为空补空

Rowid -- 分页

------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------

Oracle

表空间 tablespace
表文件 datafile


/*分为四步 */
/*第1步:创建临时表空间 */
create temporary tablespace user_temp
tempfile 'D:\oracle\oradata\Oracle9i\user_temp.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;

/*第2步:创建数据表空间 */
create tablespace test_data
logging
datafile 'D:\oracle\oradata\Oracle9i\user_data.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;

/*第3步:创建用户并指定表空间 */
create user username identified by password
default tablespace user_data
temporary tablespace user_temp;

/*第4步:给用户授予权限 */
grant connect,resource,dba to username;

sequence

create sequence emp_sequence
 INCREMENT BY 1 -- 每次加几个
 START WITH 1 -- 从1开始计数
 NOMAXVALUE -- 不设置最大值
 NOCYCLE -- 一直累加,不循环
 CACHE 10;

emp_sequence.currval
emp_sequence.nextval

select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual (伪表)

cursor -- 游标

遍历

declare
cursor emp_curis select*from emp;
emp_record emp%rowtype;
begin
open emp_cur;

loop
fetch emp_curinto emp_record;
exit when emp_cur%notfound;
dbms_output.put_line('name is:'|| emp_record.ename ||' and sal is:'|| emp_record.sal);
end loop;

close emp_cur;
end;

1=1,nvl()的技巧

exception
when .... then
SQLERRM
when others then
SQLERRM
end

-----------------------------------------------------
-----------------------------------------------------
XML

schema(xsd)










dtd

XML大小敏感,即区分大小写,标记必须成对出现

-----------------------------------------------------------
-----------------------------------------------------------
Flex(builder) -- RIA (ajax,JQuery) -- GWT

ActionScript -- flash对应的

-----------------------------------------------------------
-----------------------------------------------------------
OSGI(Open Service Gateway Initiative) -- bundle(组件)

Eclipse
WehSphere,Jboss,Glassfish,Spring DM Server
Spring DM

MANIFEST.MF

SOA BPEL WSDL webservice(Axis,xfile)

XML -- 数据描述
SOAP -- 协议
WSDL -- 服务描述
UDDI -- 唯一标识


-----------------------------------------------------------
-----------------------------------------------------------

I am GuXianJie, you can call me Justin. I have graduated from South China Agriculture University since 2005.My major is information management and information system. I have worked with J2EE 8 years and I am familiar with struts,spring,hibernate,JavaMail,Xml, portal,oracle,sql,plsql.I know telecommunications industry,medical industry, financial industry related business knowledge.
I have worked as team leader in J2EE project since 2007.In project,we worked with customer. I have analyzed customer need, designed system, managed project and also developed some core modules.I used to design designed No Order Purchase Process, Centralized Procurement(Reverse Auction) Process, Staff Reimbursement Process for Customer.Every workday,I hosted stand-up meeting at 9:30.We used Portlet to develop each small function and used Iterative Incremental style to release,assured project to adapt to changes in demand, continue to test, continuous integration.I think I'm a good team leader and I'm a person of great honesty to others. Also I am able to work under great pressure.

My hometown is Shanwei city. It is a beautiful city, back group LiangHuaShan mountain, face to Honghaiwang sea. There are a lot of delicious food, including Seafood and Land food. There are some warm spring in LiangHuaShan. So in summer we can swim in Honghaiwang and in winter we can soak in hot water (take a hot spring bath) in LiangHuaShan.

I like my hometown very much, like the mountain, like the sea, like the delicious food and also like the people.

相关文档
最新文档