application.properties配置文件不生效以及问题的解决

首先项目启动报错,发现属于是mysql配置文件问题,查看了自己的配置文件发现没有问题
1.想着会不会是谁不小心把pom里的packaging给设置错了,可以将设置一下,改成jar。很快这个被推翻了,因为并没有改动。

2.想着还可能是谁不小心在子module里面又加了一个module,虽然remove,delete,但是modules标签与还在pom还在的原因。但是看了一下也不是这个原因。

3.想着会不会是谁不小心把pom的build->resource->include的规则给改了,于是在maven的pom.xml重新声明include规则。改完以后运行试一下。发现好了。
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

如何解决

  1. 更改自己的package,如果为pom 则改为jar 或者直接注释掉
<package>jar<package>
  1. target文件没有将properties文件导入,修改pom文件为
<!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

3.查看自己的properties文件中是否写好了sql的连接

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.username=root
spring.datasource.password=1xxxx


  1. 是否为本项目不需要mysql配置,在springboot
//@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用代码方式配置 Ehcache 的缓存时间可以通过以下步骤进行: 1. 首先需要在 pom.xml 文件中添加 Ehcache 的依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>org.ehcache</groupId> <artifactId>ehcache</artifactId> </dependency> ``` 2. 在 application.properties 文件中添加 Ehcache 的配置: ```properties spring.cache.type=ehcache ``` 3. 创建 Ehcache 的配置类: ```java import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.ehcache.EhCacheCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration @EnableCaching public class EhcacheConfig { @Value("${ehcache.time-to-live-seconds}") private int timeToLiveSeconds; @Bean public CacheManagerCustomizer<EhCacheCacheManager> cacheManagerCustomizer() { return cacheManager -> cacheManager.getCacheManager().createCache("cacheName", EhCacheBuilder.newCacheConfigurationBuilder(String.class, Object.class, ResourcePoolsBuilder.heap(100)) .withExpiry(Expirations.timeToLiveExpiration(Duration.ofSeconds(timeToLiveSeconds))) .build()); } } ``` 在这个配置类中,我们使用了 `CacheManagerCustomizer` 接口来自定义 Ehcache 的缓存管理器。在 `cacheManagerCustomizer` 方法中,我们使用 `EhCacheBuilder` 来创建一个新的缓存。`EhCacheBuilder` 允许我们指定缓存的键和值类型,以及缓存的资源池大小。在这个例子中,我们使用了 `heap` 来指定缓存中最大的条目数为 100。同时,我们使用了 `withExpiry` 方法来指定缓存的过期时间为 `timeToLiveSeconds` 秒。最后,我们使用 `build` 方法来创建缓存。 4. 在需要使用缓存的方法上添加 `@Cacheable` 注解,指定缓存的名称: ```java @Service public class MyService { @Cacheable("cacheName") public Object getData() { // ... } } ``` 在这个例子中,我们使用了 `@Cacheable` 注解来标记需要被缓存的方法,并且指定了缓存的名称为 `cacheName`。 5. 在 application.properties 文件中添加缓存的过期时间: ```properties ehcache.time-to-live-seconds=604800 ``` 在这个例子中,我们将缓存的过期时间设置为 7 天,即 604800 秒。 通过以上步骤,我们就可以使用代码方式配置 Ehcache 的缓存时间了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值