当前位置: 首页 > 知识库问答 >
问题:

无法在不同环境中构建spring boot jar

施自明
2023-03-14

社区!

这是我的情况。我有spring boot申请。它是使用maven构建的,并打包在jar文件中。问题是当我在我的开发PC上构建它并运行时,一切都运行良好。如果我在我们的登台环境(即linux)上运行这个jar文件,它也运行得很好。但是,如果我在临时环境中构建它(当然,这是由我们的Jenkins服务器完成的),它在启动时会失败,例外情况是:

2016-11-28 16:11:47.777警告9443-[main]ConfigEmbeddedWebApplicationContext:上下文初始化过程中遇到异常-取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“Authentication Controller”的bean时出错:通过字段“Password Encoder”表示的不满足依赖项;嵌套异常为org.springframework.beans.factory.nosuchbeandefinitionexception:没有“org.springframework.security.crypto.bcryptpasswordencoder”类型的合格bean可用:应至少有一个合格的自动候选bean。依赖注释:{@org.springframework.beans.factory.annotation.AutoWired(required=true)}2016-11-28 16:11:47.781 INFO 9443---[main]o.apache.catalina.core.StandardService:停止服务Tomcat 2016-11-28 16:11:47.804警告9443---[main]o.s.boot.springApplication:错误处理失败(创建类路径资源[org/springframework/security/config/annotation/web/configuration/websecurityconfiguration.class]中定义S.B.D.LoggingFailureAnalysisReporter:

应用程序启动失败

描述:

Sykling.Rest.AuthenticationController中得字段passwordEncoder需要类型为“org.SpringFramework.Security.Crypto.BCrypt.BCryptPasswordEncoder”得bean,但找不到该bean.

行动:

考虑在您的配置中定义一个类型为“org.springframework.security.crypto.bcrypt.bcryptpasswordencoder”的bean。

下面是我的spring安全配置的样子:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private Logger logger = LoggerFactory.getLogger(SecurityConfiguration.class);

@Autowired private Environment environment;
@Autowired private UserService userService;

@Autowired
public void configureGlobal(AuthenticationManagerBuilder managerBuilder) throws Exception {
    managerBuilder.userDetailsService(userService);
    managerBuilder.authenticationProvider(authenticationProvider());
}

@Bean
public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}

@Bean
public DaoAuthenticationProvider authenticationProvider() {
    DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
    provider.setUserDetailsService(userService);
    provider.setPasswordEncoder(passwordEncoder());
    return provider;
}

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/css/**", "/js/**", "/partials/**", "index.html");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .antMatchers("/v1/authenticate/login", "/v1/authenticate/logout", "/").permitAll()
            .anyRequest().hasRole("USER")
        .and()
            .logout()
            .permitAll()
            .logoutSuccessUrl("/")
        .and()
            .addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class)
            .csrf().disable();
}

private AuthenticationSuccessHandler loginSuccessHandler() {
    return ((request, response, authentication) -> response.sendRedirect("/dashboard"));
}

private AuthenticationFailureHandler loginFailureHandler() {
    return ((request, response, exception) -> response.sendRedirect("/"));
}

private CsrfTokenRepository csrfTokenRepository() {
    HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository();
    repository.setHeaderName("X-XSRF-TOKEN");
    return repository;
}

}

BCryptPasswordEncoder bean定义清晰,当我在调试器中运行应用程序时,它似乎正确地自动连线。但是一旦应用程序构建在我们的linux机器上,它就无法启动。

提前致谢

共有1个答案

龙弘济
2023-03-14

以防万一有人遇到类似情况...

Bean的定义是passwordEncoder,但我尝试将其连接为encoder。一旦我指定了全名,就像passwordEncoder那样,就像预期的那样工作。

但我不知道为什么我的IDE能用AutoWilliing。

 类似资料:
  • 问题内容: 我目前在“开发”框中安装了Jenkins实例。这样可以很好地构建并且可以毫无问题地部署到我们的开发环境中。 在构建过程中,我的项目使用了一个包含诸如数据库连接URL之类的详细信息的属性文件(诸如此类的详细信息显然会因我所指向的环境而异)。 我想知道的是配置项目的最佳方法是什么,以便当我想将Jenkins构建的WAR文件发布到Production中时,它包含Production属性而不是

  • 问题内容: 我希望获得有关通过其环境促进构建的最佳方法的一些指导。 我们有3个环境,DEV,STAGING,PROD。 DEV Jenkins构建在连续集成设置中运行,因为将代码签入到Subversion中,Jenkins将运行一个新构建(干净,编译,测试,部署)。 棘手的是涉及到STAGING和PROD。 这个想法是为了能够将成功的DEV构建手动升级到STAGING。STAGING构建将签出DE

  • 我在PyCharm中创建虚拟环境时遇到问题。确切地说,3.10版中的Python是在安装过程中添加到Path的,我使用的是最新版本的PyCharm社区。 有人有类似的问题吗? 添加信息 我如何创建环境: > 文件- 位置:D:\mm\projekty\pythonProject2 标记新的虚拟环境使用(虚拟环境) 位置:D:\mm\projekty\pythonProject2\venv 基本解释

  • 本文向大家介绍使用maven的profile构建不同环境配置的方法,包括了使用maven的profile构建不同环境配置的方法的使用技巧和注意事项,需要的朋友参考一下 最近使用到了maven的profile功能,发现这个功能的确很好用也很实用,这块的知识比较多也比较乱,其实真正理解了之后非常简单,为了巩固总结知识,有个更清晰的知识体系,本文诞生了,希望能让像我一样零基础的小白一看就懂,有请戏精,闪

  • 我是C#新手,在我创建的这个随机数猜谜游戏中,我很难理解哪里出错了。我试图在第30行的do time循环中添加一个random.next命令,当我运行程序时,它会说我的猜测太高或太低,我不明白出了什么问题。这是未完成的代码: 如果我删除numberTo猜测=随机。下一个(100)1;代码工作正常,但重复相同的随机数。 请帮忙。

  • 生产环境打包要做两件事: 压缩应用代码; 使用 Vue.js 指南中描述的部署方式去除 Vue.js 中的警告。 下面是配置示例: // webpack.config.js module.exports = { // ... other options plugins: [ // short-circuits all Vue.js warning code new webp