Tag: spring boot

如何在spring cache java中配置多个缓存管理器

我希望在我的Web应用程序中配置多个Spring缓存管理器,并且我可以在项目的不同位置使用不同的缓存管理器。 有没有办法做到这一点。

如何设置Spring Boot来运行HTTPS / HTTP端口

Spring引导具有一些属性来配置Web端口和SSL设置,但是一旦设置了SSL证书,http端口就会变成https端口。 那么,我怎样才能让两个端口都在其上运行,例如:80和443同时运行? 如您所见,只有一个端口的属性,在这种情况下启用了“server.ssl”,这使得http端口自动被禁用。 ############## ### Server ### ############## server.port=9043 server.session-timeout=1800 server.ssl.key-store=file:///C:/Temp/config/localhost.jks server.ssl.key-store-password=localhost server.ssl.key-password=localhost server.ssl.trust-store=file:///C:/Temp/config/localhost.jks server.ssl.trust-store-password=localhost 我试图使用甚至Tomcat或Undertow。 我很感激任何帮助!

使用具有不同AuthenticationProviders的多个WebSecurityConfigurerAdapter(用于Web应用程序的API和LDAP的基本身份validation)

根据Spring Security Reference 5.7节 ,应该可以定义多个安全适配器。 我尝试做同样但没有成功。 在服务器重新启动之后,API的前x次正常使用基本身份validation,但是经过几次我被重定向到登录(表单)页面,这应该只针对我们的Web应用程序,而不是API调用。 我的代码: @EnableWebSecurity public class MultiHttpSecurityConfig { @Configuration @Order(1) public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter { @Autowired private Environment env; @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication(). withUser(“admin”).password(“pw_test”).roles(API_ROLE); } protected void configure(HttpSecurity http) throws Exception { http .antMatcher(“/services/**”) .authorizeRequests() .anyRequest().hasRole(API_ROLE) .and() .httpBasic() .and() .csrf() .disable(); } } […]

如何在没有XML配置的情况下定义自定义AuthenticationEntryPoint

我已经挣扎了好几天了。 我是Spring Boot的新手,并且喜欢不使用XML配置的想法。 我创建了一个RESTfull应用程序(使用JSON)。 我正在按照本教程正确配置身份validation。 我认为我设法使用Java配置重现几乎所有的配置,除了一件事 – AuthenticationEntryPoint 本教程使用http标记中的属性, 并按以下方式定义formLogin : Spring Security手册中的AuthenticationEntryPoint解释说: 可以使用元素上的entry-point-ref属性设置AuthenticationEntryPoint。 没有提到有关如何使用Java配置执行此操作的任何内容。 那么如何在没有XML的情况下“注册”我自己的restAuthenticationEntryPoint ,以防止在使用formLogin时重定向到登录表单? 下面我将提到我尝试过的内容。 谢谢你们。 在我的尝试中,发现你可以使用basicAuth定义它,如下所示: @Configuration @Order(1) public static class RestWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { if (restAuthenticationEntryPoint == null) { restAuthenticationEntryPoint = new RestAuthenticationEntryPoint(); } http .authorizeRequests() .antMatchers(“/**”).hasAnyRole(Sec.ADMIN,Sec.SUPER_USER) … .and() .httpBasic() .authenticationEntryPoint(restAuthenticationEntryPoint) 但我正在使用这样的表单登录(没有httpBasic部分): […]

如何使用Spring Boot从java属性文件中读取数据

我有一个spring boot应用程序,我想从application.properties文件中读取一些变量。 事实上,下面的代码就是这样做 但我认为这种替代方案有一个很好的方法。 Properties prop = new Properties(); InputStream input = null; try { input = new FileInputStream(“config.properties”); prop.load(input); gMapReportUrl = prop.getProperty(“gMapReportUrl”); } catch (IOException ex) { ex.printStackTrace(); } finally { … }

Spring-Data-Restvalidation器

我一直在尝试将弹簧validation器添加到spring-data-rest项目中。 我跟着并通过以下链接设置“入门”应用程序: http : //spring.io/guides/gs/accessing-data-rest/ …现在我正在尝试通过以下文档添加自定义PeopleValidator: http ://docs.spring.io/spring-data/rest/docs/2.1.0.RELEASE/reference/html/validation-chapter html的 我的自定义PeopleValidator看起来像 package hello; import org.springframework.validation.Errors; import org.springframework.validation.Validator; public class PeopleValidator implements Validator { @Override public boolean supports(Class clazz) { return true; } @Override public void validate(Object target, Errors errors) { errors.reject(“DIE”); } } …而我的Application.java类现在看起来像这样 package hello; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; […]

spring-boot – 哪一段代码实际上为springMVC注册了调度程序servlet?

我试图在spring-boot找到, WebApplicationInitializer实现实际上注册了调度程序servlet。 我没有找到SpringBootServletInitializer任何片段代码或其父类型。 相反, AbstractDispatcherServletInitializer完成了这项工作,但它是抽象的,我在Eclipse的帮助下找不到任何具体的实现。 那么,实际上调用哪一段代码来为springMVC注册调度程序servlet? 这是一个随后的问题: spring-boot如何为特定url提供服务?

自定义Zuulexception

我在Zuul有一个场景,其中URL路由的服务也可能已关闭。 因此,响应主体在JSON主体响应中被抛出500 HTTP Status和ZuulException。 { “timestamp”: 1459973637928, “status”: 500, “error”: “Internal Server Error”, “exception”: “com.netflix.zuul.exception.ZuulException”, “message”: “Forwarding error” } 我想要做的就是自定义或删除JSON响应,并可能更改HTTP状态代码。 我试图用@ControllerAdvice创建一个exception处理程序,但处理程序没有抓住exception。 更新: 所以我扩展了Zuulfilter,我可以看到它在执行错误后进入run方法,然后如何更改响应。 以下是我到目前为止所得到的。 我在某处读到了有关SendErrorFilter的内容,但我如何实现它以及它做了什么? public class CustomFilter extends ZuulFilter { @Override public String filterType() { return “post”; } @Override public int filterOrder() { return 1; } @Override public boolean shouldFilter() { return true; } […]

弹簧启动时MultipartFile的最大限制

Spring Boot可以在MultipartFile上载过程中处理最大文件大小。 我知道我可以在属性中设置maxFileSize,如multipart.maxFileSize=1Mb 。 所以,像这样我可以允许上传一个巨大的文件,比如50MB。 该应用程序在与spring boot集成的tomcat服务器上运行。 我是否还需要配置tomcat服务器。 或者文件大小是否无限制?

为什么Spring Boot Application类需要@Configuration注释?

我正在学习Spring框架,但我无法理解@Configuration注释到底意味着什么以及应该注释哪些类。 在Spring Boot文档中,据说Application类应该是@Configuration类。 Spring Boot支持基于Java的配置。 尽管可以使用XML源调用SpringApplication.run(),但我们通常建议您的主要源是@Configuration类。 试图了解@Configuration我发现使用@Configuration注释一个类表明该类可以被Spring IoC容器用作bean定义的来源。 如果是这样,那么这个应用程序类如何成为bean定义的来源? @SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan public class App { public static void main(String[] args) throws Exception { SpringApplication.run(App.class, args); } } 我几乎了解了关于Spring的大多数其他基本概念,但我无法理解@Configuration的目的或哪些类应该是@Configuration类? 有人可以请帮助。 谢谢 !!