---
title: "spring简单知识点"
author: "sharefling"
date: "2014-03-17T15:06:25Z"
tags: []
categories: ["编程语言"]
slug: "spring"
draft: false
lastmod: "2014-03-17T15:06:25Z"
id: 2032308
url: "https://sharefling.iteye.com/blog/2032308"
---

1.IOC，尽量完成构造对象所能够实现的功能

初始化

init-method="getArgs2"

@PostConstruct

    public void chushihua() {

        System.out.println("初始化");

    }

构造注入

 

析构函数

@PreDestroy

 

 

实例，静态工厂

 

各种各组件使用

@Compoonent

@Service

@Responsity

@Controller

 

监听器使用

Applicationevent,Applicationlistener

   

2.AOP

 

切入点

定义切入点

切入行为

@Before(pointcut)

@After(pointcut)

@AfterReturing(point="",return="")

@AfterThrowing(pointcut)

@Around(pointcut)

 

优先级

 

切入点表达式抒写

pointcut(修饰符+返回类型* 全限定名.方法名(..参数))

within(使用+)使用以及其子类

 

 

1.非IOC容器产生的对（领域对象）象却要依赖注入对象时需要启动ASPECTJ框架

&lt;context:spring-configured /&gt;

@Configurable(name)领域对象

其他一样配租，bean也需要

2.对于切入点new 操作，也需要引入Aspect框架来支持，比较复杂

3.引入：实现多继承

@declarePArent(value="target",interfaceimple="")

public Interface imple;

 

 

事务管理

纯spring管理mysql

1.tranactionmanager--&gt;transactiontemplate-&gt;transactioncallback-&gt;操作数据库

2.transactionmanger--&gt;装入transactiondenfination-&gt;transactionstatus-&gt;sql操作

 

 &lt;!-- 事务管理 --&gt;

    &lt;bean id="transactionmanager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;

        &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;

    &lt;/bean&gt;

    

    &lt;bean id="template" class="org.springframework.transaction.support.TransactionTemplate"&gt;

        &lt;property name="transactionManager" ref="transactionmanager"&gt;&lt;/property&gt;

    &lt;/bean&gt;

    

    &lt;bean id="transactiondao" class="mybatis.test.TransactionTest"&gt;

        &lt;property name="template" ref="template"&gt;&lt;/property&gt;

        &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;

    &lt;/bean&gt;

    

    

    &lt;!-- 事物结束 --&gt;

 

 

public class TransactionTest extends JdbcDaoSupport{

    

    private TransactionTemplate template;

 

    public TransactionTemplate getTemplate() {

        return template;

    }

 

    public void setTemplate(TransactionTemplate template) {

        this.template = template;

    }

    

    public void purchase() {

 

        template.execute(new TransactionCallbackWithoutResult(){

 

            @Override

            protected void doInTransactionWithoutResult(TransactionStatus arg0) {

                // TODO Auto-generated method stub

                

                System.out.println(getJdbcTemplate().queryForRowSet("SELECT * from db\_ac").toString());

                

                

            }

            

        }

        

        );

        

    }

    public static void main(String args\[]){

        ApplicationContext app=new ClassPathXmlApplicationContext("applicationmybatis.xml");

        TransactionTest test=(TransactionTest) app.getBean("transactiondao");

        test.purchase();

    }

}

 

连接数据库框架；

transactiontemplate实现由hibernatetemplate，进行数据库操作，灵活使用进行事务回滚使用hibernatecallback提供了hibernate session获取hibernate进行原生

hibernate操作

mybatis与spring整合无法进行事务回滚

 

 

OSGI：实现多程序基于jvm层面进行重用模块，节省内存

            BundleActivor-----&gt;BundleServide

JBPM:将业务切割为多个状态，已驱动事件为活动改变状态