通过mvn eclipse:eclipse生成eclipse工程,导入到eclipse后,启动SpringApplication.run后,系统找不到主页、数据库连接url为空等等问题,经过仔细查询,发现配置在application.properties里的配置项全部没有被spring加载。
经过测试,发现通过mvn spring-boot:run加载正常。
application.properties配置如下:
# SPRING MVC spring.view.suffix=.jsp spring.view.prefix=/WEB-INF/views/ # SOLR solr.host=http://192.168.56.11:8983/sol
使用配置项的代码如下:
@Configuration @EnableSolrRepositories(basePackages = { "org.springframework.data.solr.showcase.product" }) public class SearchContext { @Bean public SolrServer solrServer(@Value("${solr.host}") String solrHost) { return new HttpSolrServer(solrHost); } // @Bean // public SolrServer solrServer(@Value("http://192.168.56.11:8983/solr") String solrHost) { // return new HttpSolrServer(solrHost); // } @Bean public SolrServerFactory solrServerFactory(SolrServer solrServer) { return new MulticoreSolrServerFactory(solrServer); } @Bean public SolrTemplate solrTemplate(SolrServerFactory solrServerFactory) { return new SolrTemplate(solrServerFactory); } }
application.properties保存在src/main/resources下面。
经过网上查询,与分析,发现是由于eclipse配置源代码excludes过滤掉了application.properties或application.yml造成的,具体位置在: Project Properties --> Java Build Path --> Source(tab) --> Source folders on build path: [Exclusion section]
**/application.properties
将这个配置移除后,重启SpringApplication.run,加载成功!
相关推荐
使用application.properties 进行外部配置的 Spring Boot 知识点详解 Spring Boot 框架提供了多种方式来进行外部配置,今天我们将详细讲解使用 application.properties 文件来进行外部配置的方法。application....
### Spring Boot application.properties 配置详解 #### 一、概览 `application.properties` 文件是 Spring Boot 应用中非常重要的配置文件之一,用于管理应用的运行时配置。通过合理设置这些配置项,开发者可以...
activiti和springboot整合只使用application.properties配置文件,解决了jdbc长时间待机连接被收回报错。使用springProcessEngineConfiguration对activiti管理
其中,application.properties 文件是 Spring Boot 项目中的配置文件之一,用于配置应用程序的各种属性。 该配置文件将深入介绍 Spring Boot 项目中 application.properties 的超配置功能,帮助开发者更好地理解和...
《Spring Boot参考指南》是Spring Boot开发者的重要参考资料,它详细阐述了Spring Boot框架的核心特性、配置方式、自动配置原理以及如何构建微服务应用等关键知识点。Spring Boot是Java开发领域中一个极其流行的轻量...
由于 Spring Boot 中,默认会自动加载 application.properties 文件,所以简单的属性注入可以直接在这个配置文件中写。例如,我们可以定义一个 Book 类,然后,在 application.properties 文件中定义属性,按照传统...
Spring Boot中配置文件application.properties使用 Spring Boot是一个基于Java的框架,提供了许多实用的功能,包括配置文件application.properties的使用。在本文中,我们将详细介绍Spring Boot中配置文件...
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @Component @ConfigurationProperties(prefix = "custom") public class Custom...
在Spring Boot应用中集成MyBatis作为持久层框架时,我们常常希望在开发过程中能够实现XML映射文件的热加载,以便在修改了SQL语句后无需重启应用就能看到效果。这种热加载功能能显著提高开发效率。下面将详细介绍如何...
综上所述,`application.properties`文件是Spring Boot项目中的核心配置文件,它允许开发者灵活地配置应用的行为和环境。通过调整这些属性,开发者可以快速地适应不同的部署环境,以及解决开发中遇到的各种问题。
5. **配置优化**: Spring Boot默认集成了SpringLoaded,并且在`application.properties`或`application.yml`中可以调整热加载的配置,例如设置监听的源码目录、启用或禁用特定的热加载功能等。 在实际应用中,我们...
Spring Boot还支持多种外部配置方式,如application.properties或YAML文件、环境变量、命令行参数等。`ConfigFileApplicationListener`和`EnvironmentPostProcessor`接口在源码中扮演着读取和处理这些配置的关键角色...
Spring Boot 2.2及更高版本引入了一个全局懒加载机制,允许用户通过配置开启整个应用的bean懒加载,以优化启动时间和资源利用。 在传统的Spring应用中,我们可以通过在bean定义上添加`@Lazy`注解来实现单个bean的懒...
11. Developing Your First Spring Boot Application 11.1. Creating the POM 11.2. Adding Classpath Dependencies 11.3. Writing the Code 11.3.1. The @RestController and @RequestMapping Annotations 11.3.2. ...
3. **配置文件管理**:对于application.properties或application.yml文件,插件提供了一键格式化和错误检查功能,确保配置文件的正确性和规范性。 4. **运行/调试配置**:Spring Boot Assistant支持一键创建和运行...
Spring Boot的核心理念是简化配置,它通过`application.properties`或`application.yml`文件来存储全局配置。当项目变得复杂,包含多个模块时,这种单一配置文件的方式可能会导致混乱。因此,我们需要为每个模块创建...
import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "database") public class DatabaseProperties { private String url; private String ...
在 Spring Boot 中,有两个核心的配置文件,分别是 `application.properties` 和 `bootstrap.properties`。`application.properties` 用于常规的应用配置,而 `bootstrap.properties` 用于应用程序启动时的配置,...
6. **4658_06_Code**:可能涉及Spring Boot的外部配置,比如通过application.properties或YAML文件来管理配置,以及如何使用`@Value`注解注入配置属性。 7. **4658_07_Code**:可能讲解了Spring Boot的应用部署,...
spring boot 多 redis 示例spring-boot-带多redisspring boot 多 redis 示例转到路径src/main/resources/application.properties修改spring.redis.primary.host和spring.redis.secondary.host评价构建并运行它