org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为 'userServiceImpl' 的 bean 时出错
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl'
我是 Spring Boot 的新手。目前,我的 运行 项目有问题。
出现错误
17:29:07.358 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'passPolicyController' defined in file [D:\Invent\admin\build\classes\java\main\kz\bsbnb\invent\admin\controller\PassPolicyController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'passPolicyServiceImpl' defined in file [D:\Invent\admin\build\classes\java\main\kz\bsbnb\invent\admin\service\PassPolicyServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'soapServices' defined in class path resource [kz/bsbnb/invent/admin/config/SoapConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kz.bsbnb.invent.admin.soap.SOAPServices]: Factory method 'soapServices' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.saaj.SaajSoapMessageFactory]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=12=](AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at kz.bsbnb.invent.admin.AdminApplication.main(AdminApplication.java:49)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'passPolicyServiceImpl' defined in file [D:\Invent\admin\build\classes\java\main\kz\bsbnb\invent\admin\service\PassPolicyServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'soapServices' defined in class path resource [kz/bsbnb/invent/admin/config/SoapConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kz.bsbnb.invent.admin.soap.SOAPServices]: Factory method 'soapServices' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.saaj.SaajSoapMessageFactory]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=12=](AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788)
... 20 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'soapServices' defined in class path resource [kz/bsbnb/invent/admin/config/SoapConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kz.bsbnb.invent.admin.soap.SOAPServices]: Factory method 'soapServices' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.saaj.SaajSoapMessageFactory]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:635)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=12=](AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788)
... 34 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [kz.bsbnb.invent.admin.soap.SOAPServices]: Factory method 'soapServices' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.saaj.SaajSoapMessageFactory]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650)
... 48 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.saaj.SaajSoapMessageFactory]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:149)
at org.springframework.ws.support.DefaultStrategiesHelper.instantiateBean(DefaultStrategiesHelper.java:152)
at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategies(DefaultStrategiesHelper.java:134)
at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategy(DefaultStrategiesHelper.java:219)
at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategy(DefaultStrategiesHelper.java:203)
at org.springframework.ws.client.core.WebServiceTemplate.initMessageFactory(WebServiceTemplate.java:353)
at org.springframework.ws.client.core.WebServiceTemplate.initDefaultStrategies(WebServiceTemplate.java:342)
at org.springframework.ws.client.core.WebServiceTemplate.<init>(WebServiceTemplate.java:130)
at org.springframework.ws.client.core.support.WebServiceGatewaySupport.<init>(WebServiceGatewaySupport.java:65)
at kz.bsbnb.invent.admin.soap.SOAPServices.<init>(SOAPServices.java:35)
at kz.bsbnb.invent.admin.config.SoapConfig.soapServices(SoapConfig.java:50)
at kz.bsbnb.invent.admin.config.SoapConfig$$EnhancerBySpringCGLIB$5ef7a.CGLIB$soapServices(<generated>)
at kz.bsbnb.invent.admin.config.SoapConfig$$EnhancerBySpringCGLIB$5ef7a$$FastClassBySpringCGLIB$a82b797.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at kz.bsbnb.invent.admin.config.SoapConfig$$EnhancerBySpringCGLIB$5ef7a.soapServices(<generated>)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 49 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3296)
at java.base/java.lang.Class.getConstructor0(Class.java:3501)
at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2711)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:139)
... 69 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.xml.soap.SOAPException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 74 common frames omitted
并且有 class 使用 SOAP 的方法
配置class
@Configuration
public class SoapConfig {
@Bean
public Jaxb2Marshaller marshaller () {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPaths("axis2.apache.org.xsd",
"org.wso2.carbon.user.mgt.common.xsd",
"org.wso2.carbon.um.ws.service.dao.xsd",
"org.wso2.carbon.um.ws.service",
"org.wso2.carbon.user.api.xsd",
"org.wso2.carbon.user.core.xsd",
"org.wso2.carbon.user.mgt.common.xsd",
"org.wso2.carbon.identity.application.common.model.xsd",
"org.wso2.carbon.identity.base.xsd",
"org.wso2.carbon.idp.mgt.xsd",
"org.wso2.carbon.idp.mgt");
return marshaller;
}
@Bean
@Qualifier ("webServiceTemplate")
public WebServiceTemplate webServiceTemplate () {
WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setMarshaller(marshaller());
webServiceTemplate.setUnmarshaller(marshaller());
webServiceTemplate.setMessageSender(messageSender());
return webServiceTemplate;
}
@Bean
public SOAPServices soapServices (Jaxb2Marshaller marshaller) {
SOAPServices soapServices = new SOAPServices();
soapServices.setMarshaller(marshaller);
soapServices.setUnmarshaller(marshaller);
soapServices.setMessageSender(messageSender());
return soapServices;
}
private HttpUrlConnectionMessageSender messageSender () {
return new HttpUrlConnectionMessageSender() {
@Override
protected void prepareConnection (HttpURLConnection connection) throws IOException {
String credentials = String.format("%s:%s", "admin", "admin");
String encodedAuthorization = Base64.getEncoder().encodeToString(credentials.getBytes());
connection.setRequestProperty("Authorization", String.format("Basic %s", encodedAuthorization));
super.prepareConnection(connection);
}
};
}
}
服务class生成方法
public class SOAPServices extends WebServiceGatewaySupport
{
private final ObjectFactory factory = new ObjectFactory();
private final org.wso2.carbon.um.ws.service.ObjectFactory objectFactory = new org.wso2.carbon.um.ws.service.ObjectFactory();
private final org.wso2.carbon.idp.mgt.ObjectFactory idpFactory = new org.wso2.carbon.idp.mgt.ObjectFactory();
private final org.wso2.carbon.identity.application.common.model.xsd.ObjectFactory idPropFactory = new org.wso2.carbon.identity.application.common.model.xsd.ObjectFactory();
@Autowired
private WsoConstant wsoConstant;
@Autowired
@Qualifier ("webServiceTemplate")
private WebServiceTemplate webServiceTemplate;
public List<String> getAllUsername ()
{
ListUsers request = factory.createListUsers();
request.setFilter(factory.createListUsersFilter("*"));
request.setLimit(100);
ListUsersResponse listUsersResponse = (ListUsersResponse) webServiceTemplate.marshalSendAndReceive(wsoConstant.getAdminEndpoint(), request);
return listUsersResponse.getReturn();
}
}
PassPolicyService 服务class
@Service
public class PassPolicyServiceImpl implements PassPolicyService
{
private final SOAPServices soapServices;
public PassPolicyServiceImpl (SOAPServices soapServices) {this.soapServices = soapServices;}
@Override
public IdpPropPassDto getPassPolicy () throws InventException
{
IdpPropPassDto idpPropPassDto = new IdpPropPassDto();
soapServices.getIdpResidentValues().getIdpProperties().forEach((key, val) ->
{
if (key.equals("passwordPolicy.min.length"))
{
idpPropPassDto.setMinLength(Integer.parseInt(val));
}
if (key.equals("passwordPolicy.max.length"))
{
idpPropPassDto.setMaxLength(Integer.parseInt(val));
}
if (key.equals("passwordPolicy.errorMsg"))
{
idpPropPassDto.setErrorMsg(val);
}
if (key.equals("passwordPolicy.pattern"))
{
idpPropPassDto.setPassPattern(val);
}
});
return idpPropPassDto;
}
@Override
public Boolean updatePassPolicy (IdpPropPassDto idpPropPassDto) throws InventException
{
WsoPassProp passProp = soapServices.getIdpResidentValues();
passProp.getIdpProperties().clear();
passProp.getIdpProperties().put("passwordPolicy.min.length",idpPropPassDto.getMinLength().toString());
passProp.getIdpProperties().put("passwordPolicy.max.length",idpPropPassDto.getMaxLength().toString());
passProp.getIdpProperties().put("passwordPolicy.errorMsg",idpPropPassDto.getErrorMsg());
passProp.getIdpProperties().put("passwordPolicy.pattern", idpPropPassDto.getPassPattern());
return soapServices.updateResidentIdP(passProp);
}
}
我认为它正在发生,因为试图在服务 class 中使用 @Autowire 服务 class。然后我试图在 https://spring.io/guides/gs/consuming-web-service/ 中查找如何使用 SOAP。这对我没有帮助。
我不知道这里的问题是什么。你能帮帮我吗?提前谢谢你
编译器找不到 class javax/xml/soap/SOAPException。我认为这个 link 可以帮助您解决问题 java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException
我是 Spring Boot 的新手。目前,我的 运行 项目有问题。
出现错误
17:29:07.358 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'passPolicyController' defined in file [D:\Invent\admin\build\classes\java\main\kz\bsbnb\invent\admin\controller\PassPolicyController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'passPolicyServiceImpl' defined in file [D:\Invent\admin\build\classes\java\main\kz\bsbnb\invent\admin\service\PassPolicyServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'soapServices' defined in class path resource [kz/bsbnb/invent/admin/config/SoapConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kz.bsbnb.invent.admin.soap.SOAPServices]: Factory method 'soapServices' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.saaj.SaajSoapMessageFactory]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=12=](AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at kz.bsbnb.invent.admin.AdminApplication.main(AdminApplication.java:49)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'passPolicyServiceImpl' defined in file [D:\Invent\admin\build\classes\java\main\kz\bsbnb\invent\admin\service\PassPolicyServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'soapServices' defined in class path resource [kz/bsbnb/invent/admin/config/SoapConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kz.bsbnb.invent.admin.soap.SOAPServices]: Factory method 'soapServices' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.saaj.SaajSoapMessageFactory]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=12=](AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788)
... 20 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'soapServices' defined in class path resource [kz/bsbnb/invent/admin/config/SoapConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kz.bsbnb.invent.admin.soap.SOAPServices]: Factory method 'soapServices' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.saaj.SaajSoapMessageFactory]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:635)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=12=](AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788)
... 34 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [kz.bsbnb.invent.admin.soap.SOAPServices]: Factory method 'soapServices' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.saaj.SaajSoapMessageFactory]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650)
... 48 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.saaj.SaajSoapMessageFactory]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:149)
at org.springframework.ws.support.DefaultStrategiesHelper.instantiateBean(DefaultStrategiesHelper.java:152)
at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategies(DefaultStrategiesHelper.java:134)
at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategy(DefaultStrategiesHelper.java:219)
at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategy(DefaultStrategiesHelper.java:203)
at org.springframework.ws.client.core.WebServiceTemplate.initMessageFactory(WebServiceTemplate.java:353)
at org.springframework.ws.client.core.WebServiceTemplate.initDefaultStrategies(WebServiceTemplate.java:342)
at org.springframework.ws.client.core.WebServiceTemplate.<init>(WebServiceTemplate.java:130)
at org.springframework.ws.client.core.support.WebServiceGatewaySupport.<init>(WebServiceGatewaySupport.java:65)
at kz.bsbnb.invent.admin.soap.SOAPServices.<init>(SOAPServices.java:35)
at kz.bsbnb.invent.admin.config.SoapConfig.soapServices(SoapConfig.java:50)
at kz.bsbnb.invent.admin.config.SoapConfig$$EnhancerBySpringCGLIB$5ef7a.CGLIB$soapServices(<generated>)
at kz.bsbnb.invent.admin.config.SoapConfig$$EnhancerBySpringCGLIB$5ef7a$$FastClassBySpringCGLIB$a82b797.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at kz.bsbnb.invent.admin.config.SoapConfig$$EnhancerBySpringCGLIB$5ef7a.soapServices(<generated>)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 49 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3296)
at java.base/java.lang.Class.getConstructor0(Class.java:3501)
at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2711)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:139)
... 69 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.xml.soap.SOAPException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 74 common frames omitted
并且有 class 使用 SOAP 的方法
配置class
@Configuration
public class SoapConfig {
@Bean
public Jaxb2Marshaller marshaller () {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPaths("axis2.apache.org.xsd",
"org.wso2.carbon.user.mgt.common.xsd",
"org.wso2.carbon.um.ws.service.dao.xsd",
"org.wso2.carbon.um.ws.service",
"org.wso2.carbon.user.api.xsd",
"org.wso2.carbon.user.core.xsd",
"org.wso2.carbon.user.mgt.common.xsd",
"org.wso2.carbon.identity.application.common.model.xsd",
"org.wso2.carbon.identity.base.xsd",
"org.wso2.carbon.idp.mgt.xsd",
"org.wso2.carbon.idp.mgt");
return marshaller;
}
@Bean
@Qualifier ("webServiceTemplate")
public WebServiceTemplate webServiceTemplate () {
WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setMarshaller(marshaller());
webServiceTemplate.setUnmarshaller(marshaller());
webServiceTemplate.setMessageSender(messageSender());
return webServiceTemplate;
}
@Bean
public SOAPServices soapServices (Jaxb2Marshaller marshaller) {
SOAPServices soapServices = new SOAPServices();
soapServices.setMarshaller(marshaller);
soapServices.setUnmarshaller(marshaller);
soapServices.setMessageSender(messageSender());
return soapServices;
}
private HttpUrlConnectionMessageSender messageSender () {
return new HttpUrlConnectionMessageSender() {
@Override
protected void prepareConnection (HttpURLConnection connection) throws IOException {
String credentials = String.format("%s:%s", "admin", "admin");
String encodedAuthorization = Base64.getEncoder().encodeToString(credentials.getBytes());
connection.setRequestProperty("Authorization", String.format("Basic %s", encodedAuthorization));
super.prepareConnection(connection);
}
};
}
}
服务class生成方法
public class SOAPServices extends WebServiceGatewaySupport
{
private final ObjectFactory factory = new ObjectFactory();
private final org.wso2.carbon.um.ws.service.ObjectFactory objectFactory = new org.wso2.carbon.um.ws.service.ObjectFactory();
private final org.wso2.carbon.idp.mgt.ObjectFactory idpFactory = new org.wso2.carbon.idp.mgt.ObjectFactory();
private final org.wso2.carbon.identity.application.common.model.xsd.ObjectFactory idPropFactory = new org.wso2.carbon.identity.application.common.model.xsd.ObjectFactory();
@Autowired
private WsoConstant wsoConstant;
@Autowired
@Qualifier ("webServiceTemplate")
private WebServiceTemplate webServiceTemplate;
public List<String> getAllUsername ()
{
ListUsers request = factory.createListUsers();
request.setFilter(factory.createListUsersFilter("*"));
request.setLimit(100);
ListUsersResponse listUsersResponse = (ListUsersResponse) webServiceTemplate.marshalSendAndReceive(wsoConstant.getAdminEndpoint(), request);
return listUsersResponse.getReturn();
}
}
PassPolicyService 服务class
@Service
public class PassPolicyServiceImpl implements PassPolicyService
{
private final SOAPServices soapServices;
public PassPolicyServiceImpl (SOAPServices soapServices) {this.soapServices = soapServices;}
@Override
public IdpPropPassDto getPassPolicy () throws InventException
{
IdpPropPassDto idpPropPassDto = new IdpPropPassDto();
soapServices.getIdpResidentValues().getIdpProperties().forEach((key, val) ->
{
if (key.equals("passwordPolicy.min.length"))
{
idpPropPassDto.setMinLength(Integer.parseInt(val));
}
if (key.equals("passwordPolicy.max.length"))
{
idpPropPassDto.setMaxLength(Integer.parseInt(val));
}
if (key.equals("passwordPolicy.errorMsg"))
{
idpPropPassDto.setErrorMsg(val);
}
if (key.equals("passwordPolicy.pattern"))
{
idpPropPassDto.setPassPattern(val);
}
});
return idpPropPassDto;
}
@Override
public Boolean updatePassPolicy (IdpPropPassDto idpPropPassDto) throws InventException
{
WsoPassProp passProp = soapServices.getIdpResidentValues();
passProp.getIdpProperties().clear();
passProp.getIdpProperties().put("passwordPolicy.min.length",idpPropPassDto.getMinLength().toString());
passProp.getIdpProperties().put("passwordPolicy.max.length",idpPropPassDto.getMaxLength().toString());
passProp.getIdpProperties().put("passwordPolicy.errorMsg",idpPropPassDto.getErrorMsg());
passProp.getIdpProperties().put("passwordPolicy.pattern", idpPropPassDto.getPassPattern());
return soapServices.updateResidentIdP(passProp);
}
}
我认为它正在发生,因为试图在服务 class 中使用 @Autowire 服务 class。然后我试图在 https://spring.io/guides/gs/consuming-web-service/ 中查找如何使用 SOAP。这对我没有帮助。 我不知道这里的问题是什么。你能帮帮我吗?提前谢谢你
编译器找不到 class javax/xml/soap/SOAPException。我认为这个 link 可以帮助您解决问题 java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException