maven application with multi environment configuration can't deploy on tomcat
我正在尝试使用带有Maven的Spring Boot为我的Web应用程序配置多部署环境。在src / main / resources / config下创建了几个.properties文件。
db-dev.properties和db-prod.properties由db特定信息组成:
1 2 3 | db.url=jdbc:oracle:thin:@ldap://dev.com/risstg3, db.username=owner db.password=godzilla |
在同一目录中,我还具有application.properties,它可以读取这些数据库属性文件中定义的变量。
1 2 3 4 5 6 7 8 | #database info spring.datasource.driverClassName=oracle.jdbc.OracleDriver spring.datasource.url=${db.url} spring.datasource.username=${db.username} spring.datasource.password=${db.password} #hibernate config spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect |
在我的pom中设置了多个配置文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <profiles> <profile> <id>dev</id> <properties> <env>dev</env> </properties> </profile> <profile> <id>prod</id> <properties> <env>prod</env> </properties> </profile> </profiles> <build> <filters> <filter>src/main/resources/config/db-${env}.properties</filter> </filters> <resources> <resource> <directory>src/main/resources/config</directory> <filtering>true</filtering> </resource> </resources> |
Spring Boot使用我的应用程序类中的@SpringBootApplication批注来处理所有其他配置。
然后我通过使用-P选项指定配置文件来建立战争
1 2 | SEVERE: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ristoreService]] Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set |
我以为我使用
在application.properties中设置了" hibernate.dialect"
基于此线程,此错误可能不一定与hibernate方言有关。如果数据库连接不成功,您可能会看到它。我错过了什么?
是否有办法判断战争是否使用正确的配置文件创建,以及是否拾取了db- {dev} .properties中定义的变量?
这与您的设置略有不同,但我认为这将以更友好的Spring方式帮助解决问题。 Spring具有配置文件的概念。您可以创建
http://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-change-configuration-depending-on-the-environment