初学java,这是什么情况

ys324337347 2017-11-06 09:46:39


下面的xml配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

<context:component-scan base-package="com.gg.spring.dao"></context:component-scan>

<!-- 获取资源文件 -->
<context:property-placeholder location="classpath:db.properties" />

<!-- 得到C3P0数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${user}"></property>
<property name="password" value="${passWord}"></property>
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="driverClass" value="${driverClass}"></property>
</bean>

<!-- 得到 Spring 的 jdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>

<!-- 事务管理 -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>

<!-- 启用事物注解 -->
<tx:annotation-driven transaction-manager="txManager"/>

</beans>

...全文
231 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ys324337347 2017-11-07
  • 打赏
  • 举报
回复
引用 3 楼 banchanbana 的回复:
private ShopDao shopDao = new ShopDaoImpl(); dao类上是不是也做注解了? autowired后,就不能再用new的方式生成dao了
我不自动装配了 但是事物还是没效果啊
ys324337347 2017-11-07
  • 打赏
  • 举报
回复
引用 3 楼 banchanbana 的回复:
private ShopDao shopDao = new ShopDaoImpl(); dao类上是不是也做注解了? autowired后,就不能再用new的方式生成dao了
好像是 我再试试
ys324337347 2017-11-07
  • 打赏
  • 举报
回复
引用 2 楼 pany1209 的回复:
先看看知识点。。。再写代码
头晕,还不如自己捣鼓 找错
banchanbana 2017-11-07
  • 打赏
  • 举报
回复
private ShopDao shopDao = new ShopDaoImpl(); dao类上是不是也做注解了? autowired后,就不能再用new的方式生成dao了
maradona1984 2017-11-07
  • 打赏
  • 举报
回复
引用 6 楼 ys324337347 的回复:
[quote=引用 3 楼 banchanbana 的回复:] private ShopDao shopDao = new ShopDaoImpl(); dao类上是不是也做注解了? autowired后,就不能再用new的方式生成dao了
我不自动装配了 但是事物还是没效果啊[/quote] 个人觉得你应该找个例子从头到位玩一遍,因为错误的地方有点多 如果要自己解决,你得明白spring干了什么,是怎么做到的,过程太长了
李德胜1995 2017-11-06
  • 打赏
  • 举报
回复
先看看知识点。。。再写代码
ys324337347 2017-11-06
  • 打赏
  • 举报
回复
配置了<context:component-scan base-package="com.gg.spring.dao"></context:component-scan>这个就报上面的错误 不配置事物又事物不起作用,新手已经晕菜
package com.gg.spring.dao;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class DaoServiceImpl implements DaoService {
	private ShopDao shopDao = new ShopDaoImpl();

	@Transactional
	public void shopDaoExecute(int userID, int isbn) {
		int price = shopDao.getPrice(isbn);
		shopDao.updateShop(isbn);
		shopDao.updateUser(userID, price);
	}
}
这儿调用
package com.gg.spring.dao;

public class TestDao {
	private static DaoServiceImpl serviceDao = new DaoServiceImpl();

	public static void main(String[] args) {
		serviceDao.shopDaoExecute(1, 1001);
	}
}

50,549

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧