UnsatisfiedDependencyException:创建名称为'busServiceImpl'

时间:2019-05-10 11:33:47

标签: java web-services spring-boot soap spring-data-jpa

我正在尝试使用春季靴子并使用肥皂服务。我收到称为未满足的依赖项异常的错误。我已经尝试过,但无法解决。

我已经添加了xsd文件,并通过jaxb获得了pojo类。然后,我添加了用于通过spring data jpa连接数据库的实体类。我已经创建了存储库,服务,端点和配置。请任何人都可以帮助我找出解决方案。

我的代码是

BusTicket.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.com/demo/BusTicket"
    xmlns:tns="http://www.example.com/demo/BusTicket"
    elementFormDefault="qualified">

    <xs:element name="FindBusRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="BusNo" type="xs:long" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="BusDetailsResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Bus" type="tns:BusDetailsType" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>


    <xs:complexType name="BusDetailsType">
        <xs:sequence>
            <xs:element name="BusNo" type="xs:long" />
            <xs:element name="BusName" type="xs:string" />
            <xs:element name="BusType" type="xs:string" />
            <xs:element name="BusFare" type="xs:int" />
            <xs:element name="BusRoute" type="tns:BusRoutesType" />
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="BusRoutesType">
        <xs:sequence>
            <xs:element name="BoardingPoint" type="xs:string" />
            <xs:element name="DroppingPoint" type="xs:string" />
        </xs:sequence>
    </xs:complexType>


    <xs:element name="BusRouteRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="From" type="xs:string" />
                <xs:element name="To" type="xs:string" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="BusRoutesResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="AvailableBuses"
                    type="tns:AvailableBusType" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="AvailableBusType">
        <xs:sequence>
            <xs:element name="Bus" type="tns:BusDetailsType" />
        </xs:sequence>
    </xs:complexType>
</xs:schema>

BusDb.java

@Entity
@Table(name = "BUSDB")
public class BusDb {
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "busdb_Sequence")
    @SequenceGenerator(name = "busdb_Sequence", sequenceName = "BUSDB_SEQ")
    private long BusNo;

    @Column(name = "BusName")
    private String BusName;

    @Column(name = "BusType")
    private String BusType;

    @Column(name = "BusFare")
    private int BusFare;

    @ManyToOne
     @JoinColumn(name = "bus_route_id", nullable = false)
    private BusRoute busRoute;

    public BusDb() {

    }
//getter and setter

BusRoute.java

@Entity
@Table(name = "BUSROUTE")
public class BusRoute {
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "busRoute_Sequence")
    @SequenceGenerator(name = "busRoute_Sequence", sequenceName = "BUSROUTE_SEQ")
    private long bus_route_id;

    @Column(name = "Boardingpoint")
    private String Boardingpoint;
    @Column(name = "DroppingPoint")
    private String DroppingPoint;

    @OneToMany(mappedBy = "busRoute")
    private List<BusDb> buses;
//getter and setter

BusRepsitory.java

@Repository
public interface BusRepository extends CrudRepository<BusDb, Long> {

    public BusDb findBus(long busNo);
}

BusService.Java

public interface BusService {


    public BusDb getBus(long busNo);

BusServiceImpl.java

@Service
@Transactional
public class BusServiceImpl implements BusService{

    private BusRepository busrepository;



    @Autowired
    public BusServiceImpl(BusRepository busrepository) {

        this.busrepository = busrepository;
    }


    @Override
    public BusDb getBus(long busNo) {

        return busrepository.findBus(busNo);
    }

BusEndpoint.java

@Endpoint
public class BusEndPoint {
    private static final String NAMESPACE_URI = "http://www.example.com/demo/BusTicket";

    @Autowired
    private BusServiceImpl busService;

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "FindBusRequest")
    @ResponsePayload
    public BusDetailsResponse getBus(@RequestPayload FindBusRequest request) {
        BusDb bus = busService.getBus(request.getBusNo());
        BusRoute busRoute = bus.getBusRoute();
BusDetailsResponse busDetailsResponse = new BusDetailsResponse(); 
BusDetailsType busDetailsType = new BusDetailsType();
        busDetailsType.setBusNo(bus.getBusNo());
        busDetailsType.setBusName(bus.getBusName());
        busDetailsType.setBusType(bus.getBusType());
        busDetailsType.setBusFare(bus.getBusFare());



        BusRoutesType busRoutesType = new BusRoutesType();
        busRoutesType.setBoardingPoint(busRoute.getBoardingpoint());
        busRoutesType.setDroppingPoint(busRoute.getDroppingPoint());

        busDetailsType.setBusRoute(busRoutesType);
        busDetailsResponse.setBus(busDetailsType);
        System.out.println(request);
        return busDetailsResponse;
    }

在运行应用程序时,出现此错误。

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'busEndPoint': Unsatisfied dependency expressed through field 'busService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'busServiceImpl' defined in file [/Users/nagabalaji/Documents/BusTicketSystem/target/classes/com/example/demo/BusServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'busRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.example.demo.busticket.FindBusRequest
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$103/1847637306.getObject(Unknown Source) ~[na:na]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at com.example.demo.BusTicketSystemApplication.main(BusTicketSystemApplication.java:10) [classes/:na]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'busServiceImpl' defined in file [/Users/nagabalaji/Documents/BusTicketSystem/target/classes/com/example/demo/BusServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'busRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.example.demo.busticket.FindBusRequest
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$103/1847637306.getObject(Unknown Source) ~[na:na]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1247) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1167) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    ... 20 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'busRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.example.demo.busticket.FindBusRequest
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$103/1847637306.getObject(Unknown Source) ~[na:na]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1247) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1167) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    ... 34 common frames omitted
Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.example.demo.busticket.FindBusRequest
    at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:552) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:74) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:188) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:139) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:123) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:64) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:305) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport$$Lambda$470/56531119.get(Unknown Source) ~[na:na]
    at org.springframework.data.util.Lazy.getNullable(Lazy.java:211) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.data.util.Lazy.get(Lazy.java:94) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:119) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    ... 46 common frames omitted



通过使用Wsdl文件,我想在soapui中检查我的应用程序。如果我请求busno,并且需要BusDetailsResponse。那是我的例外结果。

0 个答案:

没有答案