问题描述开发平台:MacOS,开发工具:IDEA,使用框架:SpringBoot问题:无法读取yml文件中的配置,但是使用properties文件却可以.问题出现的环境背景及自己尝试过的方法正在学习yml配置文件,以前并没有使用过,但是代码是没有问题的,尝试过把项目打包给朋友,两个以上的人尝试过了,可以运行,但是在我的电脑上会出现无法读取的情况.如果将配置文件修改成properties,程序就可以正常运行.相关代码#yml配置文件server:port:9001spring:application:name:tensquare-base#微服务名称,在单个微服务中名称是没用的!在服务调用时使用的datasource:url:jdbc:mysql://127.0.0.1:3306/tensquare_base?useUnicode=true&characterEncoding=UTF8driver-class-name:com.mysql.jdbc.Driverusername:rootpassword:007397jpa:show-sql:true#打印sql语句generate-ddl:true#自动建表(如果表存在,则不建表)database:mysql#properties配置文件spring.datasource.url=jdbc:mysql://127.0.0.1:3306/tensquare_base?useUnicode=true&characterEncoding=UTF8spring.datasource.driver-class-name=com.mysql.jdbc.Driverspring.datasource.username=rootspring.datasource.password=007397server.port=9001spring.application.name=tensquare-basespring.jpa.show-sql=truespring.jpa.generate-ddl=truespring.jpa.database=mysql错误信息java.sql.SQLException:Accessdeniedforuser'root'@'172.17.0.1'(usingpassword:YES)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1714)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1224)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2190)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2221)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2016)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:776)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)~[mysql-connector-java-5.1.46.jar:5.1.46]atsun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)~[na:1.8.0_201]atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)~[na:1.8.0_201]atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)~[na:1.8.0_201]atjava.lang.reflect.Constructor.newInstance(Constructor.java:423)~[na:1.8.0_201]atcom.mysql.jdbc.Util.handleNewInstance(Util.java:425)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)~[mysql-connector-java-5.1.46.jar:5.1.46]atcom.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:117)~[HikariCP-2.7.8.jar:na]atcom.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:123)~[HikariCP-2.7.8.jar:na]atcom.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:365)~[HikariCP-2.7.8.jar:na]atcom.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:194)~[HikariCP-2.7.8.jar:na]atcom.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:460)[HikariCP-2.7.8.jar:na]atcom.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:534)[HikariCP-2.7.8.jar:na]atcom.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115)[HikariCP-2.7.8.jar:na]atcom.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)[HikariCP-2.7.8.jar:na]atorg.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:151)[spring-jdbc-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)[spring-jdbc-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)[spring-jdbc-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:324)[spring-jdbc-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.boot.jdbc.EmbeddedDatabaseConnection.isEmbedded(EmbeddedDatabaseConnection.java:123)[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.HibernateDefaultDdlAutoProvider.getDefaultDdlAuto(HibernateDefaultDdlAutoProvider.java:42)[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.lambda$getVendorProperties$1(HibernateJpaConfiguration.java:121)[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.HibernateSettings.getDdlAuto(HibernateSettings.java:60)~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate.determineDdlAuto(JpaProperties.java:250)~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate.getAdditionalProperties(JpaProperties.java:221)~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate.access$000(JpaProperties.java:172)~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.JpaProperties.getHibernateProperties(JpaProperties.java:156)~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.getVendorProperties(HibernateJpaConfiguration.java:123)[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(JpaBaseConfiguration.java:135)~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$ffbe25e4.CGLIB$entityManagerFactory$6()~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$ffbe25e4$$FastClassBySpringCGLIB$$a2b45324.invoke()~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$ffbe25e4.entityManagerFactory()~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)~[na:1.8.0_201]atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)~[na:1.8.0_201]atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)~[na:1.8.0_201]atjava.lang.reflect.Method.invoke(Method.java:498)~[na:1.8.0_201]atorg.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579)~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1250)~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099)~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541)~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089)~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859)~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]atorg.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:327)~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1255)~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1243)~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]atcom.tensquare.base.BaseApplication.main(BaseApplication.java:15)~[classes/:na]疑惑1.首先我并未在任何地方设置172.17.0.1这一ip,这是SpringBoot默认的数据库地址吗?2.为什么相同的程序,却获取不了配置文件?
idea 连接mysql的配置文件_idea如何read yml配置文件?求指导!
最新推荐文章于 2024-07-22 19:30:00 发布