ITeye博客

spring简单知识点

sharefling · 2014-03-17 15:06 · spring · 编程语言 · Markdown

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框架

<context:spring-configured />

@Configurable(name)领域对象

其他一样配租,bean也需要

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

3.引入:实现多继承

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

public Interface imple;

 

 

事务管理

纯spring管理mysql

1.tranactionmanager-->transactiontemplate->transactioncallback->操作数据库

2.transactionmanger-->装入transactiondenfination->transactionstatus->sql操作

 

 <!-- 事务管理 -->

    <bean id="transactionmanager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

        <property name="dataSource" ref="dataSource"></property>

    </bean>

    

    <bean id="template" class="org.springframework.transaction.support.TransactionTemplate">

        <property name="transactionManager" ref="transactionmanager"></property>

    </bean>

    

    <bean id="transactiondao" class="mybatis.test.TransactionTest">

        <property name="template" ref="template"></property>

        <property name="dataSource" ref="dataSource"></property>

    </bean>

    

    

    <!-- 事物结束 -->

 

 

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----->BundleServide

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。