- package cn.mu.service.product.impl;
- import javax.persistence.EntityManager;
- import javax.persistence.PersistenceContext;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import cn.mu.bean.product.ProductType;
- import cn.mu.service.product.ProductService;
- @Service
- @Transactional
- public class ProductServiceBean implements ProductService {
- @PersistenceContext
- EntityManager em;
- public void save(ProductType type){
- em.persist(type);
- }
- }
- [code]package junit.test;
- import javax.sql.DataSource;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import cn.mu.bean.product.ProductType;
- import cn.mu.service.product.ProductService;
- public class ProductTest {
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- }
- @Test
- public void runtest() {
- ApplicationContext cxt=new ClassPathXmlApplicationContext("beans.xml");
- ProductService productService=(ProductService) cxt.getBean("productServiceBean");
- productService.save(new ProductType());
- }
- }
复制代码 [/code] 找不到productServiceBean |
|