WARN: spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed

使用springboot jpa,项目启动的时候有个warn的log:

2019-04-03 14:05:59: WARN [main] o.s.b.a.o.j.JpaBaseConfiguration$JpaWebConfiguration$JpaWebMvcConfiguration JpaBaseConfiguration.java:234 - spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning

解决方案,在配置文件中加入下面这个:

spring.jpa.open-in-view=false

加入后并不会对项目产生不好的影响,具体的可以参考stackoverflow上的解答spring.jpa.open-in-view

### 解决方案分析 当Spring Boot应用程序因缺少`ServletWebServerFactory` Bean而引发`ApplicationContextException`错误时,通常表明嵌入式的Web服务器(如Tomcat、Jetty或Undertow)未被正确配置或加载。以下是可能的原因及其解决方案: #### 可能原因及解决方法 1. **缺失必要的starter依赖项** 如果项目中没有引入任何支持嵌入式Web服务器的Starter依赖项,则不会自动创建`ServletWebServerFactory` Bean。需要确保在项目的构建文件中包含至少一个合适的Starter模块,例如`spring-boot-starter-web`[^1]。 对于Maven项目,应确认`pom.xml`中有如下依赖项: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ``` 对于Gradle项目,应在`build.gradle`中添加以下内容: ```gradle implementation 'org.springframework.boot:spring-boot-starter-web' ``` 2. **禁用了默认的嵌入式Web服务器** 如果在`application.properties`或`application.yml`中显式设置了`spring.main.web-application-type=none`,则会阻止Spring Boot尝试初始化嵌入式Web服务器。如果确实不需要Web功能,可以保留此设置;否则需将其移除或改为`spring.main.web-application-type=servlet`[^2]。 3. **冲突的REST框架集成** 若项目同时集成了多个不同的REST框架(如Restlet与Spring Web),可能会导致类路径中的Bean定义发生冲突。建议仅保留一种主要的REST实现方式,并清理其他不必要的依赖项。例如,在迁移到Restlet的情况下,可删除原有的Spring Surf和Webscripts相关组件。 4. **版本兼容性问题** 需要特别注意所使用的Spring Boot版本与其他库之间的兼容性关系。例如,某些旧版插件可能不再适用于最新的Spring Boot发行版。根据官方公告显示,未来更新的重点或将转向更高版本系列而非延续当前分支维护工作[^3]。因此,请务必验证所有第三方库均匹配目标Spring Boot版本的要求。 5. **自定义配置覆盖默认行为** 当存在高度定制化的Spring上下文环境时,可能存在意外覆写标准组件实例化逻辑的情况。检查是否有地方手动注册了替代性的`WebServerFactoryCustomizer`或其他关联类型的Beans,从而干扰正常流程执行过程。 --- ### 示例代码调整 假设问题是由于缺乏基础Web Starter引起,则只需补充相应依赖即可解决问题。下面给出一段修正后的POM片段作为参考: ```xml <dependencies> <!-- Core Spring Boot functionality --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- Enable embedded Tomcat server support --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> ``` 对于那些希望完全掌控HTTP处理机制的应用场景而言,也可以自行提供具体的工厂实现实例来满足需求。比如这样: ```java import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.boot.web.server.WebServer; import org.springframework.http.server.reactive.HttpHandler; @Configuration public class CustomWebConfig { @Bean public WebServer customWebServer(HttpHandler httpHandler) { // Example using Jetty instead of default Tomcat return new JettyReactiveWebServer(httpHandler); } } ``` --- ### 总结 综上所述,针对由`ServletWebServerFactory` Bean缺失引起的启动异常情况,推荐优先核查是否存在必需的起步依赖遗漏现象,其次是排查不当属性设定或者潜在的功能替换风险因素影响到了预期的服务装配动作完成度。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值