浏览器访问路径如下:
http://127.0.0.1:8080/taotao-manager-web/insert事务文件配置如下applicationContext-trans.xml <bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource" ref="dataSource" />
</bean> <tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>

<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 切面 -->
<aop:config>
<aop:advisor advice-ref="txAdvice"
pointcut="execution(* com.taotao.service.*.*(..))" />
</aop:config>
</beans>
controller层如下@Controller
public class ItemController { @Autowired
private ItemService itemService; @RequestMapping("item/list")
@ResponseBody
public EasyUIResult getItemList(@RequestParam(value="page",defaultValue="1")Integer page,@RequestParam(value="rows",defaultValue="30")Integer rows)
{

EasyUIResult result = itemService.getItemList(page, rows);
return result;
}

@RequestMapping(value="/item/save",method=RequestMethod.POST)
@ResponseBody
public TaotaoResult addItem(TbItem item)
{
TaotaoResult result = itemService.createItem(item);
return result;
}

@RequestMapping("insert")
@ResponseBody
public TaotaoResult addItemTest(TbItem item)
{
item.setBarcode("123");
item.setCid(1L);
item.setSellPoint("java");
item.setImage("123");
item.setTitle("java");
item.setPrice(100L);
item.setNum(10);
TaotaoResult result = itemService.createItem(item);
return result;
}
}
service层如下package com.taotao.service;@Service
public class ItemServiceImpl implements ItemService {
@Autowired
private TbItemMapper mapper ;
 
public TbItem getItemById(Long id)
{

TbItemExample example = new TbItemExample();
Criteria criteria=example.createCriteria();
criteria.andIdEqualTo(id);
List<TbItem> list= mapper.selectByExample(example);
if(list!=null&&list.size()>0)
{
return list.get(0);
}
return null;
} @Override
public EasyUIResult getItemList(int page,int rows) { TbItemExample example = new TbItemExample();
PageHelper.startPage(page, rows);
List<TbItem> list= mapper.selectByExample(example);
PageInfo<TbItem> pageinfo = new PageInfo<TbItem>(list);
Long total = pageinfo.getTotal();
EasyUIResult result =  new EasyUIResult(total,list);

return result;
}
public TaotaoResult createItem(TbItem item) { item.setCreated(new Date());
item.setUpdated(new Date());
item.setStatus((byte) 1);
long id = IDUtils.genItemId();
item.setId(id);
mapper.insert(item);
return TaotaoResult.ok();
}
}
springmvc.xml配置如下
[code=java]
<context:component-scan base-package="com.taotao.controller" >
</context:component-scan>
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>

<mvc:resources location="/WEB-INF/js/" mapping="/js/**"/>
<mvc:resources location="/WEB-INF/css/" mapping="/css/**"/>


<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 设定默认编码 -->
<property name="defaultEncoding" value="UTF-8"></property>
<!-- 设定文件上传的最大值5MB,5*1024*1024 -->
<property name="maxUploadSize" value="5242880"></property>
</bean>

</beans>applicationContext-service.xml配置如下
<context:component-scan base-package="com.taotao.service">

</context:component-scan>报错如下2017-10-06 22:36:51,708 [http-8080-1] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] DispatcherServlet with name 'taotao-manager' processing GET request for [/taotao-manager-web/insert]
2017-10-06 22:36:51,709 [http-8080-1] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-[DEBUG] Looking up handler method for path /insert
2017-10-06 22:36:51,710 [http-8080-1] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-[DEBUG] Returning handler method [public com.taotao.common.pojo.TaotaoResult com.taotao.controller.ItemController.addItemTest(com.taotao.pojo.TbItem)]
2017-10-06 22:36:51,710 [http-8080-1] [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[DEBUG] Returning cached instance of singleton bean 'itemController'
2017-10-06 22:36:51,710 [http-8080-1] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Last-Modified value for [/taotao-manager-web/insert] is: -1
2017-10-06 22:36:51,733 [http-8080-1] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Creating new transaction with name [com.taotao.service.ItemServiceImpl.createItem]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-java.lang.Exception
2017-10-06 22:36:51,759 [http-8080-1] [com.alibaba.druid.pool.DruidDataSource]-[INFO] {dataSource-1} inited
2017-10-06 22:36:51,962 [http-8080-1] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Acquired Connection [com.mysql.jdbc.JDBC4Connection@148717a] for JDBC transaction
2017-10-06 22:36:51,965 [http-8080-1] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Switching JDBC Connection [com.mysql.jdbc.JDBC4Connection@148717a] to manual commit
2017-10-06 22:36:51,969 [http-8080-1] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Creating a new SqlSession
2017-10-06 22:36:51,978 [http-8080-1] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@10af66b]
2017-10-06 22:36:51,983 [http-8080-1] [org.mybatis.spring.transaction.SpringManagedTransaction]-[DEBUG] JDBC Connection [com.mysql.jdbc.JDBC4Connection@148717a] will be managed by Spring
2017-10-06 22:36:51,986 [http-8080-1] [com.taotao.mapper.TbItemMapper.insert]-[DEBUG] ==>  Preparing: insert into tb_item (id, title, sell_point, price, num, barcode, image, cid, status, created, updated) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 
2017-10-06 22:36:52,011 [http-8080-1] [com.taotao.mapper.TbItemMapper.insert]-[DEBUG] ==> Parameters: 150730061196698(Long), java(String), java(String), 100(Long), 10(Integer), 123(String), 123(String), 1(Long), 1(Byte), 2017-10-06 22:36:51.965(Timestamp), 2017-10-06 22:36:51.965(Timestamp)
2017-10-06 22:36:52,012 [http-8080-1] [com.taotao.mapper.TbItemMapper.insert]-[DEBUG] <==    Updates: 1
2017-10-06 22:36:52,012 [http-8080-1] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@10af66b]
2017-10-06 22:36:52,012 [http-8080-1] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@10af66b]
2017-10-06 22:36:52,012 [http-8080-1] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@10af66b]
2017-10-06 22:36:52,012 [http-8080-1] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@10af66b]
2017-10-06 22:36:52,012 [http-8080-1] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Initiating transaction commit
2017-10-06 22:36:52,012 [http-8080-1] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Committing JDBC transaction on Connection [com.mysql.jdbc.JDBC4Connection@148717a]
2017-10-06 22:36:52,060 [http-8080-1] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Releasing JDBC Connection [com.mysql.jdbc.JDBC4Connection@148717a] after transaction
2017-10-06 22:36:52,060 [http-8080-1] [org.springframework.jdbc.datasource.DataSourceUtils]-[DEBUG] Returning JDBC Connection to DataSource
2017-10-06 22:36:52,090 [http-8080-1] [org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain]-[DEBUG] Invoking ResponseBodyAdvice chain for body=com.taotao.common.pojo.TaotaoResult@9c7e86
2017-10-06 22:36:52,090 [http-8080-1] [org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain]-[DEBUG] After ResponseBodyAdvice chain body=com.taotao.common.pojo.TaotaoResult@9c7e86
2017-10-06 22:36:52,105 [http-8080-1] [org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor]-[DEBUG] Written [com.taotao.common.pojo.TaotaoResult@9c7e86] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@17b5381]
2017-10-06 22:36:52,105 [http-8080-1] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Null ModelAndView returned to DispatcherServlet with name 'taotao-manager': assuming HandlerAdapter completed request handling
2017-10-06 22:36:52,105 [http-8080-1] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Successfully completed request
2017-10-06 22:36:52,106 [http-8080-1] [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[DEBUG] Returning cached instance of singleton bean 'sqlSessionFactory'在数据库中插入不了
而且mysql数据库是innodb