hibernate3与spring2零配置

 ssh除了xml配置之外,还可以用标注式配置:

(1)spring 与 hibernate Annotation配置(entry)  http://zw7534313.iteye.com/blog/691546

(2)spring 与 hibernate Annotation配置(dao)   http://zw7534313.iteye.com/blog/691529

(3)Spring注解方式管理事务   http://zw7534313.iteye.com/blog/691398

(4)spring 与 hibernate Annotation配置(applicationContext.xml)       

                          http://zw7534313.iteye.com/blog/691538

(5)Test.java

public class Test {

 public static void main(String[] args) {

  ClassPathXmlApplicationContext app=new ClassPathXmlApplicationContext("applicationContext.xml");
  CompanyDao dao=(CompanyDao)app.getAutowireCapableBeanFactory()
  .createBean(CompanyDao.class);

 

CompanyService service=(CompanyService)app.getAutowireCapableBeanFactory()
  .createBean(CompanyService.class);
  TCompanyInfo tCompany=new TCompanyInfo();
  tCompany.setInfoTitle(" 2 this is a test.w");
  
  service.test(tCompany); //事务配置在service中,@Transactional事务,如果出现了SQLException,进入catch块中,再抛出一个预定义的运行时异常,才能rollback.

}

}

 

 

@Id
@Column(name = "ID_PROJECT", unique = true, nullable = false, scale = 0, insertable = false, updatable = false)
@GeneratedValue(generator = "seq_id_project",strategy=)
@GenericGenerator(name = "seq_id_project", strategy = "org.hibernate.id.enhanced.TableGenerator", parameters = { @Parameter(name = "segment_value", value = "SEQ_ID_PROJECT"), @Parameter(name = "initial_value", value = "1000"), @Parameter(name = "optimizer", value = "pooled"), @Parameter(name = "increment_size", value = "10") })
public long getIdProject() {
     return this.idProject;
}

 

 

  1. <context:annotation-config/>  
  2.   
  3.   <context:component-scan base-package="se.posten.ida">  
  4.     <context:include-filter type="regex" expression=".*DAOImpl" />  
  5.     <context:include-filter type="regex" expression=".*ServiceImpl" />  
  6.   </context:component-scan>  

<context:component-scan />还允许定义过滤器将基包下的某些类纳入或排除。

      Spring支持以下4种类型的过滤方式:

         过滤器类型         表达式范例                                                           说明

注解                 org.example.SomeAnnotation                           将所有使用SomeAnnotation注解的类过滤出来
类名指定           org.example.SomeClass                                    过滤指定的类
正则表达式        com\.kedacom\.spring\.annotation\.web\..*     通过正则表达式过滤一些类
AspectJ表达式   org.example..*Service+                                    通过AspectJ表达式过滤一些类

 

 

@PostConstruct 的 postConstruct1() 方法将在 Spring 容器启动时,创建 Boss Bean 的时候被触发执行,而标注了 @PreDestroy 注释的 preDestroy1() 方法将在 Spring 容器关闭前销毁 Boss Bean 的时候被触发执行。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值