@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.