ZFYCH_Love

Simply but Powerful

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  115 随笔 :: 1 文章 :: 36 评论 :: 18万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

1、@Autowired 自动寻找合适的类型注入,byType
2、@Qualifier("userDAOImpl") 存在多个相同类型时,指定固定的一个bean,和上面1配合使用
3、@Required 检查在配置中是否给该属性赋默认值,如果否,则报错
4、@Autowired(required=false) 对应的bean不是必须的,【但是】,如果不存在,在程序中,调用的时候,会报错,影响对该bean的使用
5、@Resource(name="guserDAOImpl1")
如果不指定参数,先按name查找,如果无,再按type查找;
如果指定name,只按name查找
如果指定type,只按type查找
6、
1)@Component("uDAO") 组件(整个类作为一个组件)
2)@Resource(name="uDAO)
3)<context:component-scan base-package="com.crm.yang.spring"></context:component-scan>
<!-- 扫描包下所有资源,配合component使用 -->

可以不指定名字(不推荐)
7、@Scope("singleton")
prototype
8、@PostConstruct
@PreDestroy(不要和propotype一起用,不起作用的)

9、代理
1)<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
2)@Aspect
@Component
public class LogInterceptor {
@Before("execution(public void com.crm.yang.spring.UserImpl.add(String))")

3)指定别名

pointcut("execution(public *com.crm.yang.spring..*.*(..)")
public void myMethod(){}

@Before("myMethod()")
poublic void XXX1(){
...
}
@Before("myMethod()")
poublic void XXX2(){
...
}

 

10、遇到事务提交不起作用情况

基本配置:

复制代码
<bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="configLocation" value="classpath:hibernate.cfg.xml">
        </property>

    </bean>
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <tx:advice id="userTransAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="add*" propagation="REQUIRED" rollback-for="true" />
            <tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/>
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut expression="execution(* com.yang.service.*.*(..))" id="userTransPoincut"/>
        <aop:advisor advice-ref="userTransAdvice" pointcut-ref="userTransPoincut"/>
    </aop:config>
复制代码

(1)有文章说是mysql表类型问题,有的表是事务安全的InnoDB和非事务安全ISAM、MyISAM)

查询:show create table t_dn_ledger_approver

发现结果是:是InnoDB。如果不是,可以修改之:

alter table tablename type=InnoDb

如果是用hibernate自动建表,而mysql数据库默认的建表类型不是InnoDb,需要修改配置文件: 

 <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> 

 

    
posted on   xiaoyang_  阅读(162)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示