Java 未能在不同的环境中构建spring引导jar
社区 这是我的情况。我有spring启动应用程序。它使用maven构建并打包在jar文件中。问题是,当我在我的开发PC上构建它并运行一切正常时。如果我在我们的登台环境(linux)上运行这个jar文件,它也会运行良好。但是,如果我在登台环境中构建它(当然,这是由我们的Jenkins服务器完成的),它在启动时会失败,只有一个例外: 2016-11-28 16:11:47.777警告9443---[main]ationConfigEmbeddedWebApplicationContext:在上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.unsatifiedPendencyException:创建名为“authenticationController”的bean时出错:通过字段“passwordEncoder”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为“org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder”的符合条件的bean可用:至少需要1个符合autowire候选条件的bean。依赖项注释:{@org.springframework.beans.factory.annotation.Autowired(required=true)} 2016-11-28 16:11:47.781信息9443---[main]o.apache.catalina.core.StandardService:停止服务Tomcat 2016-11-28 16:11:47.804警告9443---[main]o.s.boot.SpringApplication:错误处理失败(创建名为“delegatingApplicationListener”的bean时出错,该bean在类路径资源[org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]中定义:初始化bean失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration”的bean时出错:初始化bean失败;嵌套异常为org.springframework.beans.factory.NoSuchBeanDefinitionException:无bean名为“org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry”的文件(可用) 2016-11-28 16:11:47.943错误9443---[main]o.s.b.d.记录故障分析报告人:Java 未能在不同的环境中构建spring引导jar,java,spring,Java,Spring,社区 这是我的情况。我有spring启动应用程序。它使用maven构建并打包在jar文件中。问题是,当我在我的开发PC上构建它并运行一切正常时。如果我在我们的登台环境(linux)上运行这个jar文件,它也会运行良好。但是,如果我在登台环境中构建它(当然,这是由我们的Jenkins服务器完成的),它在启动时会失败,只有一个例外: 2016-11-28 16:11:47.777警告9443---[main]ationConfigEmbeddedWebApplicationContext:在上下文初
应用程序无法启动
说明: no.sykling.rest.AuthenticationController中的字段passwordEncoder需要找不到类型为“org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder”的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;
}
}
BcryptPasswordEncoderBean是明确定义的,当我在调试器中运行应用程序时,它似乎自动连接正确。但一旦应用程序构建在我们的linux机器上,它就无法启动
提前感谢以防有人遇到类似情况 Bean定义是passwordEncoder,但我试图将其连接为encoder。一旦我指定了全名,比如passwordEncoder,它就可以正常工作了 但我不知道为什么自动连线在我的IDE中起作用