du221 2018-09-28 08:52 采纳率: 100%
浏览 3959
已采纳

Spring Cloud 加@EnableDiscoveryClient后一直说yml中的数据源url有问题?

@EnableDiscoveryClient
@SpringBootApplication
//指定扫描的mapper接口所在的包
@MapperScan(basePackages = {"com.study.eurekaclient.mapper"}, sqlSessionFactoryRef = "sqlSessionFactory")
//启动注解事务管理
@EnableTransactionManagement
public class EurekaClientApplication {
private static String TYPE_ALIASES_PACKAGE = "com.study.eurekaclient.domain";
private static String MAPPER_LOCATION = "classpath:/mybatis/*.xml";
@Bean
@Autowired
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception{
final SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setTypeAliasesPackage(TYPE_ALIASES_PACKAGE);
sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_LOCATION));
return sqlSessionFactoryBean.getObject();
}
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);
}
}

server:
port: 8889
spring:
datasource:
url: jdbc:mysql://localhost:3306/dudata?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8887/eureka/
instance:
prefer-ip-address: true
thymeleaf:
cache: false
prefix: classpath:/templates/
suffix: .html
encoding: UTF-8
content-type: text/html
mode: HTML5
management:
endpoints:
web:
exposure:
include: ["*"]
base-path: /
报错信息:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

  • 写回答

1条回答 默认 最新

  • du221 2018-09-29 06:44
    关注

    自问自答一下吧,大家注意一下mybatis-spring和mybatis的版本就好了,着实是个坑啊(主要是不会用idea)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败