当前位置: 首页 > 知识库问答 >
问题:

是否访问Spring Boot应用程序的Tomcat中的externalize Application.Properties?

邹开畅
2023-03-14
package com.Mortgage.MortgageLoanAPI;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MortgageLoanApiApplication {

    public static void main(String[] args) {
        System.setProperty("spring.config.name", "application");
        SpringApplication.run(MortgageLoanApiApplication.class, args);
    }

}
package com.Mortgage.MortgageLoanAPI;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MortgageLoanApiApplication.class).properties("spring.config.name: application");
    }

}

C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.9\bin\setenv.sh

export spring_config_location=C:/Program Files/Apache Software Foundation/Apache Tomcat 8.0.9/conf/

C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.9\conf\application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/mortgage_loan
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root

但当我运行应用程序或构建应用程序时。它显示错误,因为它没有找到db连接。

2019-03-04 10:53:28.318  INFO 2872 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-03-04 10:53:28.325 ERROR 2872 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

请告诉我如何解决这个问题,或者是否有其他方法可以使用spring Boot从tomcat位置访问属性文件

共有1个答案

索嘉石
2023-03-14

请加上-

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

在类上使用注释-

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
 类似资料:
  • 完成干净的构建后,我将war文件复制到Tomcat的文件夹中。但是部署会发生两次,并且在上下文已经存在的情况下以异常结束。我错过了什么? 非常感谢您的帮助。

  • 我的程序编译了所有内容,我没有出错,但我实际上期望tomcat应该永久在端口8080上。输出中也没有Spring。在另一个项目中,我做的一切都很好。谢谢你帮助我。 我的父母: 我的tarter.class: 我的Starter-Pom: 控制台输出: 然后什么都不会发生了。谢谢你的帮助。

  • 我已经在远程服务器上安装了tomcat 9,启动后,它运行良好,我可以访问http://host_name:port_num并查看tomcat hello页面。但是,当我尝试打开manager应用程序以查看我部署的应用程序时,我的403访问被拒绝,我已经在tomcat用户xml中添加了如下角色: 我看到的错误消息是: 默认情况下,只能从与Tomcat运行在同一台机器上的浏览器访问主机管理器。如果要

  • 这是我使用SpringBoot的第一天,我试图理解体系结构,因此我开始构建一个hello world应用程序: 在我的pom.xml中,在maven-shade-plugin下,我将mainClass声明如下: 文件目标是src/main/java/com/demo/helloworld.java,该文件中的代码是: 我错过了什么?

  • 我需要在Spring-boot应用程序中使用默认的ObjectMapper作为单个实例。我是否可以简单地在应用程序内部@autowire ObjectMapper(在Spring-boot应用程序中默认创建的实例)而不创建@bean(因为我不想更改ObjectMapper的任何功能) https://docs.spring.io/spring-boot/docs/current/reference