问题标签 [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.

0 投票
2 回答
17589 浏览

java - 重复 Spring Batch 作业实例

我有一个小的示例 Spring Batch 应用程序,第一次启动时可以正常工作,但是每当我关闭应用程序并重新启动 jar 时,我总是会收到此错误:

我不确定我的工作增量器设置是否错误。但就像我说的那样,我可以启动它然后使用 Web 服务 url/jobLauncher.html来调用批处理任意次数就好了。只有在我关闭应用程序并重新启动它之后,我才会收到此错误。它想将 id 1 用于作业执行表,但 id 1 在之前的运行中已经存在。

主班

网络服务类

Spring Batch 类

0 投票
1 回答
20585 浏览

spring - 在内存数据库中使用 Spring Boot 测试

我使用 Spring Boot 创建了一个 Spring Web 项目。想了解测试周围的实践。我需要一个内存嵌入式数据库,比如 hsql 或 h2 用于我的具有初始 schema.sql 的junit。在主应用程序上,数据库可以是 mysql 或 oracle

在非 Spring Boot 项目中,我们通常会有一个单独的 applicationcontext.xml,它由 Web 应用程序引用,为了进行测试,我们将使用 applicationContext-text.xml

现在,在 Spring Boot 中,一切都是自动创建的,并且 Spring Boot 也被认为是。想知道如何为 Junits 设置一个嵌入式内存数据库和一个用于应用程序的外部数据库(如 MySQL)。

我能想到的一种解决方案是使用 Profiles。带有 2 个属性文件 application.properties 和 application-test.properties。并为我的junits使用测试配置文件。

关于我应该采取的方法的任何建议。

0 投票
1 回答
708 浏览

spring - 试图在 hadoop 集群上运行 spring boot 嵌入式 web 容器

我正在尝试运行需要与 hdfs 对话的 Spring Boot 嵌入式 Web 容器应用程序。我在 pom.xml 中包含了 spring data hadoop,但是当我在集群上运行应用程序时出现此错误

原因:java.io.FileNotFoundException: JAR entry lib/hadoop-core-1.2.1.jar!/core-default.xml not found in hdfspub-0.0.1-SNAPSHOT.jar at .jar.JarURLConnec...ction .java:122) 在 JarURLConnec...ction.java:132) 在 com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:65 1) 在 com.sun.org。 com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:772) 在 com.sun 的 apache.xerces.internal.impl.XMLVersion Detector.determineDocVersion(XMLVersionDetector.ja va:186) .org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(XMLParser.java:119) at com .sun.org.apache.xerces.internal.parsers.DOMPars er.parse(DOMParser.java:232) 位于 com.sun.org.apache.xerces.internal.jaxp。DocumentBu ilderImpl.parse(DocumentBuilderImpl.java:284) at javax.xml.parsers.DocumentBuilder.parse(DocumentBu ilder.java:180) at org.apache.hadoop.conf.Configuration.loadResource(Configuration.java:1156)

即使我看着我的罐子,我也能看到 hadoop-core-1.2.1.jar 在那里

$ unzip -l hdfspub-0.0.1-SNAPSHOT.jar | grep hadoop-core-1.2.1.jar 4203713 10-25-2013 21:04 lib/hadoop-core-1.2.1.jar

任何帮助,将不胜感激

0 投票
5 回答
124764 浏览

spring - How can I specify my .keystore file with Spring Boot and Tomcat?

I'm trying to set up Spring Security to work with Spring Boot's embedded Tomcat instance. There are quite a few basic samples that do this but I'm stuck where they leave off -- they do basic authentication over HTTP (not HTTPS).

I could probably make it work if I had access to the Tomcat configuration files (server.xml) but since Spring Boot uses an embedded Tomcat instance (which is otherwise a huge convenience), I dont have access to the Tomcat configuration files (at least, not to my knowledge).

There may be an application.properties setting for this but I haven't been able to track it down. I've seen references to a server.contextPath field in application.properties that I suspect may have something to do with replacement Tomcat config files. Even if it is related, I wouldn't know where to begin anyway -- all of the Tomcat SSL instructions I've seen start with editing an existing server.xml file, not building one from scratch.

Can this be done with Spring Boot (either by somehow specifying a snippet of server.xml or through other means)? If not, what would be the simplest way to do this? I understand that I may need to exclude the Tomcat component of Spring Boot but I'd prefer to avoid that if possible.

0 投票
1 回答
3870 浏览

spring - 扩展弹簧引导加载程序

我不明白 spring-boot-loader 的 README 文件中提供的信息

https://github.com/spring-projects/spring-boot/tree/master/spring-boot-tools/spring-boot-loader

除了spring boot在内部使用它来创建嵌入式服务器jar文件之外,spring boot loader的目的到底是什么。我们可以利用这个过程并从文件路径加载额外的 jars 以包含在类路径中吗

0 投票
1 回答
2567 浏览

spring - 指定要使用的启动器

如何指定要使用的不同启动器。我想使用 M5 版本中添加的 PropertiesLauncher

我尝试通过修改 mainfest 文件来强制它使用 PropertiesLauncher 类,它有点工作但抛出了这个错误]

2013 年 10 月 28 日 12:42:44 PM org.springframework.boot.loader.PropertiesLauncher initializeProperties

信息:找到:application.properties 2013 年 10 月 28 日下午 12:42:44 org.springframework.boot.loader.PropertiesLauncher initializePaths 信息:嵌套存档路径:[lib/]

2013 年 10 月 28 日下午 12:42:44 org.springframework.boot.loader.PropertiesLauncher getClassPathArchives 信息:从 lib/ 添加类路径条目

java.lang.IllegalStateException:在 org.springframework.boot.loader.PropertiesLauncher.getMainClass(PropertiesLauncher) 的 org.springframework.boot.loader.archive.Archive.getMainClass(Archive.java:52) 中没有指定“Start-Class”清单条目.java:298) 在 org.springframework.boot.loader.Launcher.launch(Launcher.java:53) 在 org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:343) 所以看起来它失败了包括没有指定 Start-Class 的罐子..

0 投票
2 回答
8673 浏览

java - 在 JUnit 中对带有(出)存储库的 Spring Boot 服务类进行单元测试

我正在开发一个基于 Spring Boot 的 Web 服务,其结构如下:

控制器 (REST) --> 服务 --> 存储库(如某些教程中所建议的那样)。

我的数据库连接(JPA/Hibernate/MySQL)在 @Configuration 类中定义。(见下文)

现在我想为我的 Service 类中的方法编写简单的测试,但我真的不明白如何将 ApplicationContext 加载到我的测试类中以及如何模拟 JPA / Repositories。

这是我走了多远:

我的服务等级

我的测试课:

但我得到以下异常:

原因:org.springframework.beans.factory.BeanCreationException:创建名为“sessionService”的bean时出错:注入自动装配的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配字段:私有 com.myApp.SessionRepository com.myApp.SessionService.sessionRepository;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有为依赖项找到类型为 [com.myApp.SessionRepository] ​​的合格 bean:预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者。依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}

为了完整起见:这是我的 jpa 的@Configuration:

0 投票
1 回答
2816 浏览

spring-security - 使用 OAuth 和 Spring Boot 保护 REST 服务?

如何使用 Spring Boot 保护 REST 服务 (OAuth)?

我能得到的最接近的是: http: //spring.io/guides/gs/securing-web/ http://spring.io/guides/gs/authenticating-ldap/

0 投票
3 回答
32327 浏览

java - Spring RESTful 服务作为 WAR 而不是 Tomcat 中的 JAR

我正在使用 Java Spring 创建 REST Web 服务。我已经成功加载了 STS 和详细的示例:

“本指南将引导您完成使用 Spring 创建“hello world”RESTful Web 服务的过程。” http://spring.io/guides/gs/rest-service/

但是,该教程仅到目前为止.. 我想创建一个 WAR 文件而不是一个包含 servlet 的自运行 jar,并部署该 WAR 文件。然后我找到了这个教程,并试图修改第一个教程的 build.gradle 文件。

“将 Spring Boot JAR 应用程序转换为 WAR” http://spring.io/guides/gs/convert-jar-to-war/

它似乎可以很好地构建到 .war 文件中。该服务正在我的 TOMCAT 实例的管理器中运行。但是一旦我尝试使用该服务,就会得到 404。

URL 404

我需要修改映射吗?

数据库控制器.java

现在我已经根据混合的东西创建了 .war 文件。我担心我可能错过了一些东西。

从那以后,我发现 OSX 上的 XAMPP 不包含 webapp/ 文件夹,这迫使我改为加载 Bitnami 的 Tomcat 堆栈。人们通常会基于此在 XAMPP 和其他堆栈之间切换吗?还是我错过了在 XAMPP 中创建 webapp 文件夹的东西?

0 投票
24 回答
348751 浏览

java - 如何在 Spring Boot 中添加过滤器类?

FilterSpring Boot 中的类(用于 Web 应用程序)是否有任何注释?也许@Filter

我想在我的项目中添加一个自定义过滤器。

Spring Boot 参考指南中提到了 FilterRegistrationBean,但我不知道如何使用它。