#java #spring-boot #tomcat #centos
#java #весенняя загрузка #tomcat #centos
Вопрос:
Моя среда — Centos 7, Tomcat 8 и Java 8. Я разрабатываю приложение для весенней загрузки. Я хочу экстернализировать параметры, представленные в application.properties, поэтому я копирую их во внешний файл свойств.
Здесь, приложение.файл свойств (приложение для весенней загрузки) :
spring.datasource.username= ${db.username}
spring.datasource.password= ${db.password}
Вот мой файл внешних свойств :
Содержание :
db.username=root
db.password=test
Я создал setenv.sh файл в папке tomcat / bin для добавления опции java
Вот мой setenv.sh :
Содержание :
JAVA_OPTS="$JAVA_OPTS -Dspring.config.additional-location=/home/centos/myjarvia/configuration/application.properties"
Но при запуске tomcat происходит сбой.(даже если файл журнала catalina.out показывает, что файл свойств найден…
содержимое файла catalina.out :
26-Mar-2019 22:17:04.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.39
26-Mar-2019 22:17:04.039 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Mar 14 2019 11:24:26 UTC
26-Mar-2019 22:17:04.039 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.39.0
26-Mar-2019 22:17:04.040 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
26-Mar-2019 22:17:04.040 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 3.10.0-957.5.1.el7.x86_64
26-Mar-2019 22:17:04.040 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
26-Mar-2019 22:17:04.040 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64/jre
26-Mar-2019 22:17:04.040 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_201-b09
26-Mar-2019 22:17:04.040 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
26-Mar-2019 22:17:04.040 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /opt/tomcat
26-Mar-2019 22:17:04.040 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /opt/tomcat
26-Mar-2019 22:17:04.041 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties
26-Mar-2019 22:17:04.041 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
26-Mar-2019 22:17:04.041 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dspring.config.additional-location=/home/centos/myjarvia/configuration/application.properties
26-Mar-2019 22:17:04.041 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
26-Mar-2019 22:17:04.041 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
26-Mar-2019 22:17:04.041 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
26-Mar-2019 22:17:04.041 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
26-Mar-2019 22:17:04.041 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/opt/tomcat
26-Mar-2019 22:17:04.041 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/opt/tomcat
26-Mar-2019 22:17:04.041 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/opt/tomcat/temp
26-Mar-2019 22:17:04.042 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environm$
26-Mar-2019 22:17:04.147 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
26-Mar-2019 22:17:04.167 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
26-Mar-2019 22:17:04.200 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
26-Mar-2019 22:17:04.202 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
26-Mar-2019 22:17:04.203 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 584 ms
26-Mar-2019 22:17:04.242 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
26-Mar-2019 22:17:04.242 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.39
26-Mar-2019 22:17:04.282 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/opt/tomcat/webapps/MyJarviaBackDevice-1.0.war]
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.4.RELEASE)
2019-03-26 22:17:08.449 INFO 30878 --- [ost-startStop-1] c.t.mc.myjarvia.MyJarviaBackDeviceApp : Starting MyJarviaBackDeviceApp v0.0.1 on serveur-1 with PID 30878 (/opt/tomcat/webapps/MyJarvia$
2019-03-26 22:17:08.468 INFO 30878 --- [ost-startStop-1] c.t.mc.myjarvia.MyJarviaBackDeviceApp : No active profile set, falling back to default profiles: default
2019-03-26 22:17:08.558 INFO 30878 --- [ost-startStop-1] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplica$
2019-03-26 22:17:09.926 INFO 30878 --- [ost-startStop-1] o.s.b.f.xml.XmlBeanDefinitionReader : Loading XML bean definitions from class path resource [context/dataBinder_context.xml]
2019-03-26 22:17:11.916 INFO 30878 --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of ty$
2019-03-26 22:17:11.988 INFO 30878 --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfigura$
2019-03-26 22:17:12.001 INFO 30878 --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuratio$
2019-03-26 22:17:12.002 INFO 30878 --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHand$
2019-03-26 22:17:12.021 INFO 30878 --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.Jsr250MetadataSourceC$
2019-03-26 22:17:12.033 INFO 30878 --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'jsr250MethodSecurityMetadataSource' of type [org.springframework.security.access.annotati$
2019-03-26 22:17:12.036 INFO 30878 --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityC$
2019-03-26 22:17:12.056 INFO 30878 --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.Delegat$
2019-03-26 22:17:12.065 INFO 30878 --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [org.apache.camel.spring.boo$
2019-03-26 22:17:12.110 INFO 30878 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3552 ms
2019-03-26 22:17:13.138 INFO 30878 --- [ost-startStop-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-03-26 22:17:14.389 ERROR 30878 --- [ost-startStop-1] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
java.sql.SQLException: Access denied for user '${db.username}'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) ~[mysql-connector-java-5.1.47.jar:5.1.47]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978) ~[mysql-connector-java-5.1.47.jar:5.1.47]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914) ~[mysql-connector-java-5.1.47.jar:5.1.47]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871) ~[mysql-connector-java-5.1.47.jar:5.1.47]
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1714) ~[mysql-connector-java-5.1.47.jar:5.1.47]
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1224) ~[mysql-connector-java-5.1.47.jar:5.1.47]
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2199) ~[mysql-connector-java-5.1.47.jar:5.1.47]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2230) ~[mysql-connector-java-5.1.47.jar:5.1.47]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2025) ~[mysql-connector-java-5.1.47.jar:5.1.47]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:778) ~[mysql-connector-java-5.1.47.jar:5.1.47]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) ~[mysql-connector-java-5.1.47.jar:5.1.47]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_201]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_201]
Я не понимаю, что не так
Ответ №1:
просто добавьте это в свой файл внешних свойств
spring.datasource.username= указать имя пользователя базы данных
spring.datasource.password= указать пароль базы данных
это автоматически переопределит
и удалите другие вещи, такие как db.username и тому подобное
Комментарии:
1. Это не решает проблему. Может ли это быть проблемой с разрешениями для файла или папки? поскольку tomcat был установлен с помощью пользователя tomcat: [root@serveur-1 opt]# ls -l ==> результат: drwx—— 9 tomcat tomcat 4096 27 марта 23:21 tomcat