1.duboo的@Service注解和@Transactional冲突
1.服务提供方添加pom文件添加依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
2.在spring配置文件添加数据连接和事务后
<!-- 1.配置数据源 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- 1.1.数据库驱动 -->
<property name="driverClassName"
value="com.mysql.jdbc.Driver"></property>
<!-- 1.2.连接数据库的url -->
<property name="url"
value="jdbc:mysql://localhost:3306/morning?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true"></property>
<!-- 1.3.连接数据库的用户名 -->
<property name="username" value="root"></property>
<!-- 1.4.连接数据库的密码 -->
<property name="password" value="root"></property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 申明式事务 --><!-- 可通过注解控制事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
**3.打包重启duboo提供者和服务消费者时再次调用服务时消费者出现空指针
**
controller注入对象则找不到UserService主要原因是在事务扫描时UserService会生成代理对象在sun包下 找不到UserService对象无法注入出现空指针
解决办法:
如下加入:proxy-target-class=“true”
<!-- 申明式事务 --><!-- 可通过注解控制事务 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
然后将@Service修改如下
@Service(interfaceClass = UserService.class)
在进行扫描时指定扫描对象 不用代理对象