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

如何解决SpringBoot2.2.6-Release与Jasypt-Spring-Boot-Starter3.0.2冲突

洪雅健
2023-03-14

场景:我有一个使用springboot+springmvc的web应用程序,springParent的版本是2.2.6版本,我尝试使用jasypt-spring-boot-starter加密数据源用户名和密码,版本是3.0.2。maven clean包(war)是成功的,但在Tomcat中运行失败。下面是错误消息和配置截图:

错误消息:

2020-04-20 23:57:44.195  INFO 8840 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-04-20 23:57:44.211  INFO 8840 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-04-20 23:57:44.211  INFO 8840 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-04-20 23:57:44.320  INFO 8840 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-04-20 23:57:44.320  INFO 8840 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1561 ms
2020-04-20 23:57:44.398  WARN 8840 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginLogDao': Unsatisfied dependency expressed through method 'setJdbcTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdbcTemplate' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfiguration.class]: Unsatisfied dependency expressed through method 'jdbcTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-04-20 23:57:44.398  INFO 8840 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-04-20 23:57:44.414  INFO 8840 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-04-19 17:39:48.592 ERROR 6892 --- [           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:
  application:
    name: yue-alvin-forum
  profiles:
    active: common,dev
server:
  port: 8096
  servlet:
    context-path: /smart

spring:
  mvc:
    view.prefix: /jsp/
    view.suffix: .jsp

jasypt:
  encryptor:
    password: alvin@20200418
    algorithm: PBEWithMD5AndDES
spring:
  datasource:
    type: org.apache.commons.dbcp2.BasicDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/sampledb?serverTimezone=UTC&characterEncoding=utf-8
    username: ENC(P+BapX4qZq6CpkfAZjdNug==)
    password: ENC(e8WREgEjQQs4zOL0re8Jg2JakDoi/ABmOf9a9VpVSR8=)
    dbcp2:
      max-wait-millis: 10000
      min-idle: 5
      initial-size: 5
      validation-query: SELECT 1
      connection-properties:
        characterEncoding: utf8

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>yue-alvin-forum</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-context</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>3.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <version>9.0.33</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.18</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-dbcp2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.12</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.3.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

共有1个答案

壤驷承
2023-03-14

尝试在application-dev.yml中为“jdbc-url”更改“url”

 类似资料:
  • Jasypt Spring Boot 为 Spring Boot 项目中的属性源(property sources)提供加密支持。 有三种方法可以在项目中集成 jasypt-spring-boot: 如果 Spring Boot 项目中使用了 @SpringBootApplication 或者 @EnableAutoConfiguration ,在项目里添加jasypt-spring-boot-s

  • 如上所示,必须把loader.min.js去掉window.Babel对象才有值,这是为什么呢?是哪里冲突了吗?

  • 本文向大家介绍浅谈spring boot 集成 log4j 解决与logback冲突的问题,包括了浅谈spring boot 集成 log4j 解决与logback冲突的问题的使用技巧和注意事项,需要的朋友参考一下 现在很流行springboot的开发,小编闲来无事也学了学,开发过程中遇见了log4j日志的一个小小问题,特此记载。 首先在pox.xml中引入对应的maven依赖: 然后在src/r

  • 我的项目root目录下pom文件添加了springboot的依赖 前端的目录下pom中添加了,要用到@restcontroller 然后一堆包冲突,是不是我的做法有错误,还是版本问题?

  • 问题内容: //这是我的代码,我正在代理工作… //以下错误出现在我的控制台上 我正在使用以下罐子 问题答案: 该班已搬迁到另一个包中的HttpClient 4.4。 从4.4开始 将您的httpcore版本升级到至少4.4即可解决该问题。

  • C STLunordered_map如何解决冲突? 看着http://www.cplusplus.com/reference/unordered_map/unordered_map/,它说“唯一的键容器中的两个元素不能有相同的键。” 这意味着容器确实在解决碰撞。然而,那一页并没有告诉我它是如何做到的。我知道一些解决冲突的方法,比如使用链表和/或探测。我想知道的是c STL无序_映射是如何解决它的。