草庐IT

java - 在 Spring Boot 1.4 中不推荐使用 FilterRegistrationBean。*

我在我的项目中升级了SpringBoot依赖项,我意识到某些类,例如FilterRegistrationBean,已被弃用。你知道如何在SpringBoot1.4.1中实现过滤器吗?过滤bean@BeanpublicFilterRegistrationBeanfilterRegistrationBean(){AuthenticationFilterf=newAuthenticationFilter();FilterRegistrationBeanregistrationBean=newFilterRegistrationBean();registrationBean.setFilter

spring - 如何在 Spring Boot 中为文件上传指定临时目录?

我正在使用SpringBoot,需要让用户上传文件进行处理。现在,文件上传到/home/username/git/myproject这不是很好。如何让Spring将这些文件上传到一个临时目录中,该目录将通过应用程序重新启动(或其他方式)定期清除?这是我尝试过的……但它不起作用。文件仍然保存到我的工作目录中。publicclassApplicationimplementsCommandLineRunner{/**Thisdoesn'tseemtowork.*/@BeanMultipartConfigElementmultipartConfigElement(){MultipartConf

spring - 为什么 Spring Boot web app 启动后会立即关闭?

使用STS,如果我使用最新的SpringBoot导入"RestService"GettingStarted项目并选择"RunAsSpringBootApp",它会启动,然后立即关闭。查看调试日志,Spring出于某种原因决定该项目不是Web应用程序,但我不知道为什么。如果我从SpringBoot1.1.1.RELEASE切换到1.0.1.RELEASE,项目按预期工作,并找到默认的Tomcat嵌入式服务器。我在1.1.1发行说明中找不到任何暗示配置更改或任何内容的内容?更新:重现和记录输出的步骤我正在运行STS3.6.0.M1和Spring4.0.5以及SpringBoot1.1.1。

spring - 无法访问 Spring Boot Actuator "/actuator"端点

我能够访问http://localhost:8081/health、/status、/env、等端点/metrics、/shutdown但not/actuator或/loginfo端点。遇到异常。{"timestamp":1455929182552,"status":404,"error":"NotFound","message":"Nomessageavailable","path":"/actuator"}如何访问http://localhost:8081/actuator端点? 最佳答案 从SpringBoot版本2.0.1开

java - 如何向 Spring Boot 项目添加基于方法的安全性?

我想为SpringBoot项目添加基于方法的安全性。看来我只需要添加PermissionEvaluator和MethodSecurityExpressionHandlerbean,用@EnableGlobalMethodSecurity(prePostEnabled)注释我的WebSecurityConfigurerAdapter=true)和带有@PreAuthorize("isAuthenticated()andhasPermission(#param,'somePermissionName')")的方法。但是在添加了一个PermissionEvaluatorbean@Beanpu

spring - 更改部署为 war 的 spring-boot 应用程序的默认欢迎页面

我试图找到一种方法来更改作为生产中的war部署的spring-boot应用程序的默认欢迎页面,但是如果没有web.xml文件,我无法找到一种方法。根据文档,我们可以使用EmbeddedServletContainerFactory和以下代码:@BeanpublicEmbeddedServletContainerFactoryservletContainer(){TomcatEmbeddedServletContainerFactoryfactory=newTomcatEmbeddedServletContainerFactory();TomcatContextCustomizercon

spring - 从 Spring boot 1.2 升级到 1.5.2 后,Tomcat 8.5 启动期间出现 FileNotFoundException

我升级了SpringBoot从1.2.0到1.5.2。升级后,Tomcat8.5在启动期间抛出FileNotFoundException。下面是其中一个异常,它抛出超过~10个类似的异常。我不知道这些jar的用途,换句话说,我没有添加对于pom.xml.中的这些jarsINFO:StartingServletEngine:ApacheTomcat/8.5.11Apr06,20173:53:57PMorg.apache.tomcat.util.scan.StandardJarScannerscanWARNING:Failedtoscan[file:/C:/Users/myname/.m2

java - Spring Boot 禁用/错误映射

我正在使用SpringBoot创建一个API,因此希望禁用/error映射。我在application.properties中设置了以下props:server.error.whitelabel.enabled=falsespring.mvc.throw-exception-if-no-handler-found=truespring.resources.add-mappings=false但是当我点击/error我得到:HTTP/1.1500InternalServerErrorServer:Apache-Coyote/1.1Content-Type:application/json

spring - 如何在 Thymeleaf 和 Spring Boot 中显示消息?

我创建了一个使用Thymeleaf作为模板引擎的SpringBootWeb应用程序。我将MessageSource配置为在子文件夹中查找消息:@BeanpublicMessageSourcemessageSource(){finalReloadableResourceBundleMessageSourcemessageSource=newReloadableResourceBundleMessageSource();messageSource.setBasename("i18n/messages");messageSource.setFallbackToSystemLocale(fal

具有多个 DispatcherServlet 的 Spring Boot,每个 DispatcherServlet 都有自己的 @Controller

基本上我想将我的应用程序分成两部分。每个部分都有自己的安全内容和自己的@Controller。@Services应该可以从两个部分访问。所以我想,我应该得到2个DispatcherServlet。一个监听/admin/*,第二个监听其他所有内容(/)。每一个都有自己的AnnotationConfigWebApplicationContext所以我可以对@Controllers进行单独的组件扫描。而且由于SpringBoot提供了一个开箱即用的DispatcherServlet监听/,我想,我可以添加第二个:@ConfigurationpublicclassMyConfig{@Bean(