我正在尝试连接Spring Data JPA对象,以便我可以生成DAO代理(又名存储库) – 不使用Spring bean容器。 不可避免的是,我会被问到为什么要这样做:这是因为我们的项目已经在使用Google Guice(并且在使用Gin和GWT的UI上),我们不想维护另一个IoC容器configuration,所有由此产生的依赖关系。 我知道我们可以使用Guice的SpringIntegration ,但这是最后的手段。 看起来,所有东西都可以手动连接对象,但由于没有很好的文档logging,所以我很困难。 根据Spring Data用户指南, 独立使用仓库工厂是可能的。 不幸的是,这个例子显示了RepositoryFactorySupport是一个抽象类。 经过一番search,我设法findJpaRepositoryFactory JpaRepositoryFactory实际上工作得很好,除了它不会自动创build事务。 事务必须手动pipe理,否则什么都不会持久化到数据库: entityManager.getTransaction().begin(); repositoryInstance.save(someJpaObject); entityManager.getTransaction().commit(); 问题原来是@Transactional注释不会自动使用,并需要一个TransactionInterceptor 值得庆幸的是,在返回之前, JpaRepositoryFactory可以进行callback以将更多的AOPbuild议添加到生成的Repository代理中: final JpaTransactionManager xactManager = new JpaTransactionManager(emf); final JpaRepositoryFactory factory = new JpaRepositoryFactory(emf.createEntityManager()); factory.addRepositoryProxyPostProcessor(new RepositoryProxyPostProcessor() { @Override public void postProcess(ProxyFactory factory) { factory.addAdvice(new TransactionInterceptor(xactManager, new AnnotationTransactionAttributeSource())); } }); 这是事情做得不好的地方。 通过代码中的debugging器, TransactionInterceptor确实创build了一个事务 – […]
当我调用一个使用SessionFactory.getCurrentSession()的DAO方法时,我得到这个exception。 DAO类用@Transactional注释,我也在应用程序上下文configuration文件中声明了<tx:annotation-driven/> 。 我可以调用执行HQL查询的DAO方法,但每当我调用一个首先获得Hibernate会话的DAO方法时,就会遇到下面的exception: SEVERE: Failed to save the object. org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63) at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622) at gov.noaa.ncdc.cmb.persistence.dao.GenericDaoHibernateImpl.getCurrentSession(GenericDaoHibernateImpl.java:56) at gov.noaa.ncdc.cmb.persistence.dao.GenericDaoHibernateImpl.saveOrUpdate(GenericDaoHibernateImpl.java:187) 我有以下应用程序上下文configuration文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:flex="http://www.springframework.org/schema/flex" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <!– ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ –> <!– […]
我想更新Spring RestTemplate使用的jackson映射器的SerializationConfig.Feature …属性,任何想法如何我可以到它或我可以/应该configuration它。
我使用STS(弹簧工具套件)+ maven插件。 每当我使用maven-clean运行我的应用程序时,我会看到以下错误: [INFO] Scanning for projects… [INFO] [INFO] ———————————————————————— [INFO] Building hhsystem ui 1.0.0-SNAPSHOT [INFO] ———————————————————————— [INFO] [INFO] — maven-clean-plugin:2.4.1:clean (default-clean) @ ui — [INFO] Deleting C:\Users\Nikolay_Tkachev\workspace\HHSystem\UI\target [INFO] ———————————————————————— [INFO] BUILD FAILURE [INFO] ———————————————————————— [INFO] Total time: 0.471s [INFO] Finished at: Mon Oct 21 12:34:33 MSK 2013 [INFO] Final Memory: 2M/90M [INFO] ———————————————————————— [ERROR] […]
Dave Syer(SpringSource)在他的博客中写道 : 不幸的是,关于commons-logging的最糟糕的事情,以及使得新工具不受欢迎的东西也是运行时发现algorithm。 为什么? 它的运行时发现algorithm有什么问题? 性能?
到目前为止,我所研究的大多数人都认为Apache Shiro易于使用,并且易于与CAS集成(用于SSO等)。 只是问有没有人有使用过这两种方法的经验,哪一方面比其他方法好?
我正在从一个XMLconfiguration到annoations。 我想转换一个会话作用域的bean <aop:scoped-proxy> 这可以通过注释完成,如果不能,我还能做些什么来保持这个声明的正常工作? 编辑:我有兴趣在Spring 2.5中做这个
我有一个在logback.xml中定义的logback appender,它是一个数据库appender,但是我很好奇,是否有任何方法来使用我自己的连接池定义为一个bean在java中configurationappender。 我发现类似的东西,但从来没有真正的答案。
这是工作: <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> … 但升级到上述版本打破了它。 使用Spring 3.1.Release和Hibernate 4.0.0.FINAL创buildSessionFactory bean的正确方法是什么? 部署错误是: 嵌套的exception是java.lang.NoClassDefFoundError:Lorg / hibernate / cache / CacheProvider; 编辑 已经添加了我自己的答案,这为我解决了。
在服务器端使用JSR 303 beanvalidation时,使用Javascript执行客户端表单validation(最less代码重复)的最佳方式是什么? 我目前正在使用Spring 3和Hibernate Validator 。