Tag: spring boot

具有身份validation的Spring Boot项目结构

我正在学习Spring启动及其模块,但我希望避免学习不良实践。 那么你能告诉我通常使用什么项目结构吗? 我正在使用这个结构: com +- example +- myproject +- Application.java | +- config | +- CustomSecurityConfig.java (extends WebSecurityConfigurerAdapter) | +- domain | +- Customer.java | +- repository | +- CustomerRepository.java | +- service | +- CustomerService.java | +- web +- CustomerController.java 现在我需要实现JWT身份validation,所以我有了新的类: 用于安全filter链的CustomAuthFilter.java AuthenticationManager的CustomUserDetailsS​​ervice.java CustomEntryPoint.java用于处理exception 用于管理jwt令牌的CustomJwtService.java 用于其他端点的CustomAuthController.java,如/ login,/ logout,/ create-user,/ reset-password 你能告诉我这个class的哪个店吗? 我有两个想法: 创建安全文件夹并将其放在一起 将文件拆分为现有文件夹,如:CustomAuthFilter.java […]

使用在同一容器中运行的多个应用程序在Spring Boot中外部化配置

我正在构建多个Spring Boot应用程序,这些应用程序将部署在同一个servlet容器中。 但是我很难让Spring Boot按照我想要的方式使用外部化配置文件,而不是像框架那样。 情况: 多个Spring Boot应用程序将部署在单个servlet容器(WAR文件)中 配置文件的位置将通过JVM属性spring.config.location 嵌入式部署不是一种选择 问题: 由于应用程序部署在同一JVM上,因此属性spring.config.location对于所有应用程序具有相同的值。 我希望我们的应用程序都使用相同的配置文件命名(application.properties),因此指定spring.config.name不是一个选项。 我想要的是什么: 无需设置spring.config.name因为配置名称应该在所有应用程序中标准化(常量) 外部化配置属性应覆盖在已部署的WAR中打包的application.properties中的值 配置文件特定配置(application- {profile})应该是可能的 代码中没有硬编码的配置位置 在每个应用程序目录布局中组织配置文件: $ {spring.config.location} /app1/application.properties $ {spring.config.location} /app2/application.properties $ {spring.config.location} /app3/application.properties 问题: 是否有某种机制来影响或覆盖外部配置文件的加载或解析? 是否有其他方法可以获得理想的结果?

Spring Boot – 在部署时启动后台线程的最佳方式

我在Tomcat 8中部署了一个Spring Boot应用程序。当应用程序启动时,我想在Spring Autowires的后台启动一个工作线程,并带有一些依赖关系。 目前我有这个: @SpringBootApplication @EnableAutoConfiguration @ComponentScan public class MyServer extends SpringBootServletInitializer { public static void main(String[] args) { log.info(“Starting application”); ApplicationContext ctx = SpringApplication.run(MyServer.class, args); Thread subscriber = new Thread(ctx.getBean(EventSubscriber.class)); log.info(“Starting Subscriber Thread”); subscriber.start(); } 在我的Docker测试环境中,这很好用 – 但是当我将它部署到Tomcat 8中的Linux(Debian Jessie,Java 8)主机时,我从未看到“Starting Subscriber Thread”消息(并且线程未启动)。

如何在spring boot remote shell中将参数和选项传递给自定义远程shell命令?

这是后续问题 如何使用spring shell在spring boot web应用程序中构建控制台命令? 根据以上问题的建议我正在尝试spring boot remote shell。 我已按照此文档创建了自定义命令, http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-remote-shell.html#production-ready-extending-the-remote-shell 但在现实世界的用例中,我们主要有参数和选项来命令。 在doc中没有提到如何定义它们以便用户在运行命令时应该通过。 这是很好的解释,并且很容易在spring-shell中完成。 http://docs.spring.io/spring-shell/docs/current/reference/htmlsingle/#simple-application https://projects.spring.io/spring-shell/ 但我们不能使用带弹簧靴的弹簧shell。 这些用例的可靠生产就绪解决方案是什么? 更新: 在CRaSH doc上获得了解决方案 http://www.crashub.org/1.3/reference.html#developping_commands 登录到shell后我可以在命令列表中看到myCommand,但是当我运行命令时, 但我得到例外 “Could not create command commandName instance”. 我试图在命令中使用spring beans,所以我做了自动assembly,例如 package commands; import org.crsh.cli.Argument; import org.crsh.cli.Command; import org.crsh.cli.Usage; import org.crsh.cli.Option; import org.crsh.cli.Required; import org.crsh.command.BaseCommand; import org.crsh.command.InvocationContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @Usage(“My […]

Spring Boot是否支持servlet 2.5自动配置?

我想创建一个部署在Google AppEngine基础架构上的Spring Boot应用程序。 GAE目前仅支持servlet 2.5 Web应用程序。 是否可以将Spring Boot – 使用自动配置 – 与旧式web.xml结合使用? 我可以使用一个指向@Configration类的contextClass / contextConfigLocation,包括@EnableAutoConfiguration吗? 所有Spring Boot示例似乎都使用带有main方法的简单Application类来运行应用程序。 所以我想知道Spring Boot是否支持使用web.xml作为启动应用程序的起点?

我可以为Spring Boot应用创建多个入口点吗?

在Spring Boot中 ,需要指定一个主类,它是应用程序的入口点。 通常,这是一个带有标准主方法的简单类,如下所示; @SpringBootApplication public class MySpringApplication { public static void main(String [] args) { SpringApplication.run(MySpringApplication.class, args); } } 然后,在运行应用程序时,将此类指定为主入口点。 但是,我想使用config来运行我的代码,使用config来定义它,而不使用不同的jar ! (我知道重建jar会让我指定一个替代的主类,但这实际上给了我两个应用程序,而不是一个!所以,我怎么能这样做来利用一个带有两个主类的jar并选择一个通过Spring application.yml文件?

目标org.springframework.boot的执行默认值:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed:Source必须引用现有文件

我想使用maven-jar-plugin来构建diff分类器jar,比如: mvn deploy:部署-p debug,classifier-demo-0.0.1-debug.jar mvn deploy:部署-p test,classifier-demo-0.0.1-test.jar。 但失败了: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Source must refer to an existing file pom.xml: 4.0.0 org.springframework.boot spring-boot-starter-parent 1.2.3.RELEASE org.lenic classifier-demo 0.0.1 1.7 local-repo file://D:\repo test test debug true debug org.springframework.boot spring-boot-maven-plugin org.apache.maven.plugins maven-jar-plugin ${classifier}

spring-boot-maven-plugin可用于非弹簧项目吗?

spring-boot-maven-plugin主要目标是将spring boot应用程序打包到具有所有依赖项的可执行jar中。 它可以用于没有弹簧或弹簧靴的项目吗? 我不是使用spring依赖项,而只是用于加载依赖jar的类加载器机制。

避免将Spring Framework特定服务显示为Swagger接口的一部分

我使用的是spring-boot-starter-parent 1.3.3.RELEASE。 我无法在Swagger UI中禁用以下端点。 需要禁用: – Entity Metadata Services profile-controller repository-controller 我使用代码禁用了以下端点。 已禁用的端点: – environment-manager-mvc-endpoint generic-postable-mvc-endpoint restart-mvc-endpoint 码:- public Docket appHierarchyServiceApi() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(Predicates.not(RequestHandlerSelectors.basePackage(“org.springframework.boot”))) .paths(PathSelectors.any()).build() 如何在Swagger UI中禁用配置文件和存储库控制器? 请提供您的意见。

如何在Spring Boot中覆盖Spring Security默认配置

我对Spring Boot有一点问题。 我非常喜欢Spring Boot,它是非常方便的工具,它让我可以专注于逻辑实现而不是bean配置。 但是……我想覆盖默认的Spring Security配置。 我创建了SecurityConfig类,Spring Boot在启动时加载了该类。 我可以在地址/ bean上看到我的配置bean。 但配置仍然是默认的(我猜)。 @Configuration @EnableWebSecurity public class SecurityConfiguration extends WebSecurityConfigurerAdapter { public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{ auth.inMemoryAuthentication().withUser(“user”).password(“password”).roles(“USER”); } protected void cofigure(HttpSecurity http) throws Exception{ http.authorizeRequests() .antMatchers(“/app/”).permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage(“/login”) .permitAll() .and() .logout() .permitAll() .and() .csrf() .and() .exceptionHandling() .accessDeniedPage(“/error”); } } 我已使用username:user声明用户,并传递:password。 我还宣称,Spring Security必须允许任何用户查看索引站点:localhost:port / app […]