我正在尝试从我的JAR导入配置类。 config类的bean初始化如下:
@Configuration
@ConditionalOnMissingBean(Config.class)
public class Config {
@Bean
@ConditionalOnMissingBean(Base64.class)
public Base64 base64(){
return new DatatypeBaseConverter64();
}
}
我试图以这种方式从我项目的配置类中的jar中导入这个类:
@Configuration
@EnableAutoConfiguration
@Import({Config.class})
public class Configure {
//@Bean
//public JwtService permissionsService()throws URISyntaxException,IOException{
// return new JwtService(new SecretKeyProvider());
//}
}
当我运行我的项目时,我收到以下错误。
Field base64Converter in com.p2s.security123.service.JwtService required a bean of type 'com.p2s.security123.DatatypeBaseConverter64' that could not be found.
Action:
Consider defining a bean of type 'com.p2s.security123.DatatypeBaseConverter64' in your configuration.
我的Base64界面:
public interface Base64 {
String encode(byte[] bytes);
byte[] decode(String base64);
}
JwtService类:
@Component
@Service
public class JwtService {
@Autowired
DatatypeBaseConverter64 base64Converter;
......
}
DatatypeBaseConverterBase64类:
public class DatatypeConverterBase64 implements Base64 {
@Override
public String encode(byte[] bytes) {
return printBase64Binary(bytes);
}
@Override
public byte[] decode(String base64) {
return parseBase64Binary(base64);
}
}
JwtService,Base64,DatatypeConverterBase64和config在我的jar中,Configure类在我的项目中。 感谢。