Tag: spring boot

列出所有已部署的rest端点(spring-boot,jersey)

是否可以使用spring boot列出我配置的所有rest端点? 执行器在启动时列出所有现有路径,我想要类似于我的自定义服务,所以我可以检查启动是否所有路径都配置正确并使用此信息进行客户端调用。 我该怎么做呢? 我在服务bean上使用@Path / @GET注释,并通过ResourceConfig#registerClasses @GET注册它们。 有没有办法查询所有路径的配置? 更新:我通过注册REST控制器 @Bean public ResourceConfig resourceConfig() { return new ResourceConfig() { { register(MyRestController.class); } }; } Update2:我希望有类似的东西 GET /rest/mycontroller/info POST /res/mycontroller/update … 动机:当spring-boot应用程序启动时,我想打印出所有已注册的控制器及其路径,因此我可以停止猜测要使用哪些端点。

如何将Spring Boot application.properties外部化到tomcat / lib文件夹

我需要一个免费的,可部署的war,myapp1.war,它可以从tomcat / lib文件夹中检索配置文件。 由于我有其他Web应用程序共存于同一个Tomcat:myapp2.war,myapp3.war,我需要这样的布局: tomcat/lib/myapp1/application.properties tomcat/lib/myapp2/application.properties tomcat/lib/myapp3/application.properties 通过这种方式,我可以在战争中构建war文件而不需要任何属性文件,并在任何服务器上部署。 我已经阅读了Spring文档,但它解释了如何在作为jar运行时设置位置: java -jar myapp.jar –spring.config.location=classpath:/default.properties,classpath:/override.properties 对于多个共存战争文件的情况,我无法弄清楚如何做到这一点。 我想知道这是否可行,还是应该放弃Spring Boot并回到传统的Spring MVC应用程序。

@TestPropertySource和@PropertySource不适用于JUnit

看起来我在Spring 4.1.1中使用Spring Boot 1.2.6.RELEASE做的事情根本不起作用。 我只是想访问应用程序属性并在必要时使用测试覆盖它们(不使用hack手动注入PropertySource) 这不起作用.. @TestPropertySource(properties = {“elastic.index=test_index”}) 这也不是.. @TestPropertySource(locations = “/classpath:document.properties”) 也不是.. @PropertySource(“classpath:/document.properties”) 完整测试案例.. @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) @TestPropertySource(properties = {“elastic.index=test_index”}) public class PropertyTests { @Value(“${elastic.index}”) String index; @Configuration @TestPropertySource(properties = {“elastic.index=test_index”}) static class ContextConfiguration { } @Test public void wtf() { assertEquals(“test_index”, index); } } 导致 org.junit.ComparisonFailure: Expected :test_index Actual :${elastic.index} 似乎3.x和4.x之间存在很多相互矛盾的信息,我找不到任何可行的信息。 […]

如何处理Spring Boot重定向到/ error?

我遇到了与此问题相同的问题,使用Spring Boot 1.3.0并且没有使用@RestController注释我的控制器,只有@Path和@Service 。 正如该问题中的OP所说, 对我来说,这不是明智的事 我也无法理解他们为什么会重定向到/错误。 我很可能错过了一些东西 ,因为我只能向客户回馈404或200。 我的问题是他的解决方案似乎不适用于1.3.0,所以我有以下请求流:让我们说我的代码抛出NullPointerException 。 它将由我的一个ExceptionMapper处理 @Provider public class GeneralExceptionMapper implements ExceptionMapper { private static final Logger LOGGER = LoggerFactory.getLogger(GeneralExceptionMapper.class); @Override public Response toResponse(Throwable exception) { LOGGER.error(exception.getLocalizedMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } 我的代码返回500,但不是将其发送回客户端,而是尝试将其重定向到/ error。 如果我没有其他资源,它会发回404。 2015-12-16 18:33:21.268 INFO 9708 — [nio-8080-exec-1] o.glassfish.jersey.filter.LoggingFilter : 1 * Server has received a request […]

使用注释@SpringBootApplication进行配置

我有Spring Boot配置的问题。 我使用https://start.spring.io/创建了基本的Spring Boot项目 我有一个问题,配置仅适用于子目录中的类: 我试过注释@ComponentScan但它没有帮助。 你知道我能用这个做什么吗?

Spring Boot外部化属性不起作用

我看了下面的线程,并按照那里给出的东西。 我的财产覆盖仍然没有发生 1) Spring Boot – 外部化属性 2) 特定于配置文件的属性启用 3) Spring Boot外部配置 我在tomcat 8.0.33和Spring boot starter web上,并在我的setenv.sh中得到了这个 export JAVA_OPTS=”$JAVA_OPTS -Dlog.level=INFO -Dspring.config.location=file:/opt/jboss/apache-tomcat-8.0.33/overrides/ -Dspring.profiles.active=dev” 在overrides文件夹中,我有2个文件 1) application.properties 2) application-dev.properties application.properties中只有一个条目 spring.profiles.active=dev 我看到正确的log.level被提供给我的代码,这意味着这个命令正在运行。 它只是因为我为什么我的覆盖没有按预期发生而无能为力 我的工作区中没有任何`PropertyPlaceholderConfigurer代码。 我甚至不确定我是否需要1 请帮忙!!!

如果应用程序使用另一个时区而不是MySQL,则Hibernate会保存/检索日期减去日期

我在MACHINE_A上使用时区GMT + 3在tomcat上启动了一个应用程序。 我使用带有时区UTC的MACHINE_B上启动的远程mysql服务器。 我们使用spring-data-jpa来表示持久性。 作为问题的一个例子,我将展示存储库: public interface MyRepository extends JpaRepository { Optional findByDate(LocalDate localDate); } 如果我通过localDate 2018-09-06 ,我得到的实体的日期是2018-09-05 (前一天) 在日志中我看到: 2018-09-06 18:17:27.783 TRACE 13676 — [nio-8080-exec-3] ohtype.descriptor.sql.BasicBinder : binding parameter [1] as [DATE] – [2018-09-06] 我搜索了很多这个问题并找到了几篇内容相同的文章(例如https://moelholm.com/2016/11/09/spring-boot-controlling-timezones-with-hibernate/ ) 所以,我有以下application.yml : spring: datasource: url: jdbc:mysql://localhost:3306/MYDB?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC username: root password: ***** jpa: hibernate: naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl properties: hibernate: […]

Spring Security 5:没有为id“null”映射PasswordEncoder

我正在从Spring Boot 1.4.9迁移到Spring Boot 2.0以及Spring Security 5,我正在尝试通过OAuth 2进行身份validation。但是我收到此错误: java.lang.IllegalArgumentException:没有为id“null”映射PasswordEncoder 从Spring Security 5的文档中,我了解到密码的存储格式已更改。 在我当前的代码中,我创建了我的密码编码器bean: @Bean public BCryptPasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } 但它给了我以下错误: 编码密码看起来不像BCrypt 所以我按照Spring Security 5文档更新编码器: @Bean public PasswordEncoder passwordEncoder() { return PasswordEncoderFactories.createDelegatingPasswordEncoder(); } 现在,如果我能在数据库中看到密码,那么它就是存储的 {bcrypt}$2a$10$LoV/3z36G86x6Gn101aekuz3q9d7yfBp3jFn7dzNN/AL5630FyUQ 随着第一个错误消失,现在当我尝试进行身份validation时,我得到以下错误: java.lang.IllegalArgumentException:没有为id“null”映射PasswordEncoder 为了解决这个问题,我尝试了Stackoverflow的以下所有问题: Spring Boot PasswordEncoder错误 Spring Oauth2。 密码编码器未在DaoAuthenticationProvider中设置 这是一个类似于我的问题,但没有回答: Spring Security 5 – 密码迁移 注意:我已将加密密码存储在数据库中,因此无需再在UserDetailsService进行编码。 在Spring security […]

Spring中的Websocket身份validation和授权

我一直在努力用Spring-Security正确实现Stomp(websocket) 身份validation和授权 。 对于后代,我会回答我自己的问题,提供指导。 问题 Spring WebSocket文档(用于身份validation)看起来不清楚ATM(恕我直言)。 我无法理解如何正确处理身份validation和授权 。 我想要的是 使用登录名/密码validation用户。 防止匿名用户通过WebSocket进行连接。 添加授权层(用户,管理员,…)。 Principal可以在控制器中使用。 我不想要的 在HTTP协商端点上进行身份validation(因为大多数JavaScript库不会与HTTP协商调用一起发送身份validation标头)。

公共和私人资源使用不同的路径Jersey + Spring启动

我正在使用Spring boot + Jersey + Spring安全性,我想拥有公共和私有端点,我想要一个架构如下: / rest – 我的根上下文 / public – 我想将我的公共端点放在这个上下文中,它必须在/rest/public/pings类的根上下文中 / private – 我想将我的私有端点放在这个上下文中,它必须在/rest/private/accounts类的根上下文中 我的配置如下: 泽西配置: @Configuration @ApplicationPath(“/rest”) public class RestConfig extends ResourceConfig { public RestConfig() { register(SampleResource.class); } } Spring安全配置: @Configuration public class SecurityConfiguration extends WebSecurityConfigurerAdapter { …….. protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers(“/rest/public/**”).permitAll(); http.antMatcher(“/rest/**”).authorizeRequests().anyRequest().fullyAuthenticated().and().httpBasic(); http.csrf().disable(); } } […]