问题标签 [spring-boot]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - Spring-boot:不能使用持久性
我已经为此付出了很多天,并且-尽管我学到了很多东西-开始感到绝望。
我已经尝试了关于这个优秀问题的所有建议:
我曾经使用无处不在的 HibernateUtil 类进行了这项工作,但被告知要在此处转换为普通的 JPA 样式:
不幸的是,我无法让 bean 注入在 spring-boot 中正常工作。这是我的尝试:
Spring JPA (Hibernate) 没有符合条件的 bean 类型:javax.persistence.EntityManagerFactory
在这条道路上经过大量工作后,我最终得到了一个空实体管理器。我发现了这个并开始认为它不起作用:
在 Tomcat 6 中使用 JPA2:@PersitenceContext 不起作用,EntityManager 为空
在我看来, EntityManagerFactory 绝对应该是 spring-boot 创建的任何上下文中的 bean,但是......无论如何。我认为至少这会起作用:
应用启动:
控制器:
道:
/src/main/resources/persistence.xml:
它不起作用:
--- 添加信息 ---
聚甲醛:
java - Spring Boot jdbc 数据源自动配置在独立 tomcat 上失败
在尝试在独立的 tomcat (7) 实例上部署和启动 spring boot 应用程序时,我们遇到了一个问题,即找不到自动配置的 spring 数据源 bean 并引发了相应的异常:
简单的 jdbc spring.datasource 在 application.properties 中正确配置,应用程序本身与嵌入式 tomcat 实例完美运行,作为独立的 spring boot 应用程序。
似乎 application.properties 文件无法正确读取和/或处理,或者在数据源自动配置完成之前触发了一些其他 bean 的注入(例如 REST 控制器中的服务)。
不使用嵌入式 tomcat 时是否需要任何额外配置?或者有没有人遇到过类似的问题?
简单的应用和配置:
应用程序属性:
数据源使用示例:
Pom 父级和依赖项:
启动失败自动配置报告:
谢谢
java - Autowired property is null - Spring Boot Configuration
I am stuck with null values in an autowired property. I am hoping I could get some help.
We are using for the project spring-boot version 0.5.0.M6.
The four configuration files with beans are in one package and are sorted by "area":
- Data source configuration
- Global method security configuration (as we use Spring-ACL)
- MVC configuration
- Spring Security configuration
The main method that bootstraps everything is in the following file:
The first file that holds the data source configuration beans is as follows (I have omitted some method body parts to make it more readable):
And here is the next configuration file, that depends on the data source from above. It has about 20 beans related to ACL configuration, but it fails on the firsts bean that uses data source:
Basically invoking aclService()
throws an error as dataSource
is null. We have tried ordering the configuration files by implementing the Ordered
interface. We also tried using @AutoConfigureAfter(RootDataSourceConfig.class)
but this did not help either. Instead of doing @Autowired
on the DataSource
we also tried injecting the RootDataSourceConfig
class itself, but it was still null. We tried using @DependsOn
and @Ordered
on those beans but again no success. It seems like nothing can be injected into this configuration.
The console output at the startup is listing the beans in the order we want them, with data source being the first. We are pretty much blocked by this.
Is there anything weird or unique we are doing here that is not working? If this is as designed, then how could we inject data source differently?
Repo: github
java - Spring Boot 在 JBoss 上不起作用
我正盯着Spring Boot,我试图创建网站上可用的示例(http://projects.spring.io/spring-boot/#quick-start)。当我将该示例作为独立应用程序 (.jar) 以及作为 Tomcat 服务器中的 Web 应用程序 (.war) 运行时,一切正常。
但是当我将在 Tomcat 上工作的同一个 .war 文件移动到JBoss 7.1服务器时,它就不再工作了。我收到此错误:
我不知道为什么会这样。我用谷歌搜索但找不到与 Spring Boot 相关的任何内容。有人可以帮我吗?完整的堆栈跟踪如下。提前致谢!
java - 如何使用 Spring Boot 注册辅助 servlet?
我有一个额外的 servlet 需要在我的应用程序中注册。但是,使用 Spring Boot 及其 Java Config,我不能只在web.xml
文件中添加 servlet 映射。
如何添加额外的 servlet?
spring - 使用 Spring Boot 在嵌入式 Tomcat 服务器上部署资源
我有一个项目,其中来自多个来源的数据被处理成一些数据结构。在程序完成构建这些结构后,我希望它设置一个服务器,使用户能够手动微调这些结构。我决定使用 Spring Boot 设置的嵌入式 Tomcat 服务器上的 Spring MVC 正是我所需要的。
我想使用 Thymeleaf 作为视图技术,因此做了
和
但是即使在 有一个视图文件/resources/views/greeting.html
,服务器对 URL 的回复http://localhost:8080/greeting
是
在调试器中单步执行代码后,似乎在某些时候,ServletContext
应该将视图文件作为流返回,在临时文件夹中看起来像
这是空的。
现在我知道我需要
在服务器启动时将资源部署到临时文件夹
让服务器在资源所在的目录中运行
我的问题只是我不知道该怎么做,或者哪种方法最好。有些东西告诉我 1 是更好的智慧,但欢迎提出任何建议。
编辑
好的,我最终得到了一些似乎有效的东西。虽然 Joe 的回答确实帮助我上路了,但似乎我不得不以一种让我困惑的方式更改我的 Maven 配置。
将模板greeting.html
放入/resources/templates/greeting.html
并添加resources
到构建路径后,出现错误
换句话说,Thymeleaf 似乎没有正确配置。经过一番摆弄后,我最终将spring-boot-starter-parent
in的版本pom.xml
从更改0.5.0.BUILD-SNAPSHOT
为0.5.0.M6
:
并从 Thymeleaf 依赖项中删除版本标签
在此之后,它起作用了。
有人可以解释为什么我需要更改版本spring-boot-starter-parent
才能从中删除版本标签thymeleaf-spring3
,以及为什么有必要这样做?
hibernate - 从 spring-boot-starter-data-jpa 0.5.0.M6 升级到 0.5.0.BUILD-SNAPSHOT 会导致“TransactionRequiredException:没有正在进行的事务”
我正在使用 Spring Batch 教程http://spring.io/guides/gs/batch-processing/中的示例代码,其中我将 ItemWriter 的实现从JdbcBatchItemWriter换成JpaItemWriter作为JPA 的实验。当我在 POM 中使用spring-boot-starter-parent:0.5.0.M6时,示例应用程序运行没有错误。
当我切换到spring-boot-starter-parent:0.5.0.BUILD-SNAPSHOT如下图所示,
我收到以下运行时错误:
在升级之前,示例工作正常,因此导致此错误的依赖代码发生了一些变化。我的 Spring 配置如下所示:
我没有明确定义事务管理器,我想知道这里是否需要。我很困惑,因为该样本以前有效。
更新:使用最新的 Spring Boot 更新,现在我收到错误消息:
我不再在 BatchConfiguration 中配置 JpaTransactionManager,我允许 Spring Boot 尽可能多地进行配置。
java - 在 Tomcat 中部署 Spring-Boot WAR 时崩溃
我设法使用java -jar
命令运行了一个 spring-boot Web 应用程序。但是在将打包字段改成war(在pom.xml中)并构建成war时,在tomcat 7中运行失败。
我将 pom.xml 的父级设置为:
并且:
我得到的错误是:
我的问题是:
- 这里会发生什么以及如何克服这个问题?
- 使用spring-boot真的安全吗?因为嵌入式服务器库似乎会影响其部署到 j2ee 容器中的可靠性。我知道,它仍然是里程碑版本。
tomcat - 使用 Spring Boot 在嵌入式 Tomcat 服务器设置上的 Spring MVC 应用程序的路径变量中的非 ASCII 符号
我正在使用使用 Spring Boot 设置的 Spring MVC 构建服务,我希望能够在 URL 中包含任意 unicode 字符。
通过环顾网络,我最终得到
和
模板“单词”只是从模型中打印出单词。
当我启动服务器并进入http://localhost:8080/word/æøå
Chrome 时,响应页面(和终端)上打印的文本是
我认为当丹麦字母æøå
实际上以 UTF-8 编码时,我认为这是 ISO-8859-1 对丹麦字母的解释。
查看 Chrome 的网络检查器,我发现它实际上查询http://localhost:8080/word/%C3%A6%C3%B8%C3%A52
的确实似乎是 UTF-8 中字符串的 URL 编码。
谁能解释为什么尽管有这种配置,Spring 仍不将路径变量解析为 UTF-8,以及如何制作?
关于是否CharacterEncodingFilter
真正解决了这个问题似乎有不同的看法。至少,在我的另一个(非引导)Spring 项目中,我web.xml
用来注册CharacterEncodingFilter
. 在这里,它成功地用于使 POST 正文解析为 UTF-8,但我也无法让它适用于那里的路径变量。
这个答案表明它应该在Tomcat的设置中进行配置。如果是这样,如何在嵌入式服务器上完成?
spring - 使 @ResponseBody 注释的 Spring (Boot) MVC 控制器方法返回 UTF-8
我正在使用 Spring Boot 构建 Spring MVC 服务,并希望能够以 UTF-8 编码的纯文本形式返回字符串。按照这个描述,我认为唯一需要做的就是添加 bean 方法
但是root
方法在
æøå
响应ISO-8859-1 而不是 UTF-8 中的字符串,除非我取消注释该produces
部分,在这种情况下它实际上返回 UTF-8。消息转换器在这里似乎没有任何作用。
按照这种方法,我确认该 bean 已实际注册。除了这个 bean 之外,我还注册了一个EmbeddedServletContainerFactory
and CharacterEncodingFilter
,如另一个问题中所述,尽管我认为这与这里无关。
有人可以解释注册的HttpMessageConverter
实际作用,以及如何使@ResponseBody
-annotated 控制器方法返回 UTF-8 而不必produces
每次都提供?
编辑
正如评论中所讨论的那样,为了使接受的答案起作用,我必须将 Spring Boot 的版本从升级0.5.0.M6
到 ,0.5.0.BUILD-SNAPSHOT
并且为了防止输出垃圾标头,请调用converter.setWriteAcceptCharset(false)
.StringHttpMessageConverter