du221 2018-09-28 00: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-28 22:44
    关注

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

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部