我是 broadleaf 应用程序的新手。我能够使用 tomcat + mysql 集成运行应用程序。现在我想继续开发以根据我的要求定制站点项目。
我坚持在阔叶网站模块中坚持不懈。我尝试使用em.merge
返回我的实体但不将其保存在数据库中并尝试@Transactional(value="blTransactionManager")
但仍然存在问题。我在 applicationContext-servlet.xml
<aop:config>
<aop:pointcut id="blMyStoreDao" expression="execution(* com.mycompany.dao.StoreDaoImpl.save*(..))"/>
<aop:advisor advice-ref="blTxAdvice" pointcut-ref="blMyStoreDao"/>
</aop:config>
这是我的控制器代码
newStore.setCustomer(customer);
newStore.setProductList(new ArrayList<ProductImpl>());
Store getStore=store.save(em, newStore);
System.out.println(getStore.getCustomer().getUsername());
System.out.println("customer fetched: "+customer.getEmailAddress());
这是我的daoimpl代码
@Repository("blMyStoreDao")
@Transactional(value="blTransactionManager")
public class StoreDaoImpl implements StoreDao {
@PersistenceContext(unitName="blPU")
protected EntityManager em;
@Transactional(value="blTransactionManager")
public Store save(EntityManager em, Store store) {
System.out.println(em);
System.out.println(store.getCustomer().getUsername());
Store s= em.merge(store);
return s;
}
}
但它也没有解决我的问题。
代码运行完美,但它不会将我的实体保存在数据库中。
任何人的帮助。在此先感谢
答案 0 :(得分:0)
<aop:config>
,尤其是在applicationContext-servlet.xml
中(如果它应该位于根应用程序上下文中的任何地方)@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER
注释您的方法applicationContext.xml
中设置了默认组件扫描,以扫描com.mycompany.core
。我建议验证您的dao实际上是由Spring扫描并初始化为Spring bean。实体管理器没有被注入的事实表明它没有被Spring正确加载。验证这种方法的一种方法是添加@PostConstruct
方法并打印一些内容或设置断点以验证它是否被击中。