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 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?