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

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 电脑出问题了,说是usbmom注册表没
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网