0

I'm trying to launch a web server, and am getting this error code:

WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productcatalog': Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for service {http://ProductCatalog.net/}ProductCatalog.

Here is my ProductCatalog.java file:

package net.ProductCatalog;

import java.util.ArrayList;


import java.util.Iterator;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.*;



@WebService(targetNamespace = "http://ProductCatalog.net/", portName = "ProductCatalogPort", serviceName = "ProductCatalogService")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public class ProductCatalog {       
    

        public static ArrayList<Product> CreateCatalog() {
        
    ArrayList<Product> listOfProducts = new ArrayList<Product>();

    Product apples = new Product("Apples", "001", new Float("5.99"), 50);
    Product bananas = new Product("Bananas", "002", new Float("3.49"), 25);
    Product pears = new Product("Pears", "003", new Float("4.25"), 15);
    
    // add objects to ArrayList
    listOfProducts.add(apples);
    listOfProducts.add(bananas);
    listOfProducts.add(pears);
    
    return listOfProducts;
    }
    

    @WebMethod(operationName = "AddProduct", action = "urn:AddProduct")
    public String AddProduct( @WebParam(name = "arg0") String name, @WebParam(name = "arg1") String code, @WebParam(name = "arg2") float price, @WebParam(name = "arg3") int quantity) {
        // retrieve existing product list
        ArrayList<Product> catalog = ProductCatalog.CreateCatalog();
        
        // create the new product listing
        Product addition = new Product(name, code, price, quantity);
        
        // check to see if product listing already exists - skipped for now
        
        // add new product listing to the existing product list
        catalog.add(addition);
        return "Successfully added Product";
    }
    


    @WebMethod(operationName = "DeleteProduct", action = "urn:DeleteProduct")
    public boolean DeleteProduct( @WebParam(name = "arg0") String name ) {
        // retrieve existing product list
        ArrayList<Product> catalog = ProductCatalog.CreateCatalog();
        
        // search for named product
        // remove Product from ArrayList if same as named product
        Iterator<Product> it = catalog.iterator();
        while (it.hasNext())
        {
            Product x = it.next();
            if (x.getName().equals(name))   {           
                it.remove();
                return true;
            }
        }
        return false;
    }
    
    

    @WebMethod(operationName = "SearchProduct", action = "urn:SearchProduct")
    public Product SearchProduct( @WebParam(name = "arg0") String name ) {
        // retrieve existing product list
        ArrayList<Product> catalog = ProductCatalog.CreateCatalog();
        
        // search for product name in list 
        Iterator<Product> it = catalog.iterator();
        while (it.hasNext())
        {
            Product x = it.next();
            if (x.getName().equals(name))   {   
                return x;
            }
        }
        
        return null;
    }   
    

    @WebMethod(operationName = "GetPrice", action = "urn:GetPrice")
    public float GetPrice( @WebParam(name = "arg0") String name ) {
        
        ArrayList<Product> catalog = ProductCatalog.CreateCatalog();
        
        // search for product name in list 
        Iterator<Product> it = catalog.iterator();
        while (it.hasNext())
        {
            Product x = it.next();
            if (x.getName().equals(name))   {   
                return x.getPrice();
            }
        }
        
        return (float) 0.0;
    } 
}

Here is my Product.java file:

    package net.ProductCatalog;

class Product {
    private String name;
    private String code;
    private float price;
    private int quantity;
    
    public Product(String name,
                String code,
                float price,
                int quantity) {
        this.name = name;
        this.code = code;
        this.price = price;
        this.quantity = quantity;
    }
    
    // getters
    
    public String getName() {
        return name;
    }
    public String getCode() {
        return code;
    }
    public float getPrice() {
        return price;
    }
    public int getQuantity() {
        return quantity;
    }
    
    // setters
    
    public void setName(String name) {
        this.name = name;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public void setPrice(float price) {
        this.price = price;
    }
    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }
}
And here is my WSDL file:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="ProductCatalogService" targetNamespace="http://ProductCatalog.net/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ProductCatalog.net/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema">
  <import namespace="http://ProductCatalog.net/" schemaLocation="productcatalog_schema1.xsd"/>
</schema>
  </wsdl:types>
  <wsdl:message name="DeleteProductResponse">
    <wsdl:part name="parameters" element="tns:DeleteProductResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="DeleteProduct">
    <wsdl:part name="parameters" element="tns:DeleteProduct">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="SearchProductResponse">
    <wsdl:part name="parameters" element="tns:SearchProductResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="AddProductResponse">
    <wsdl:part name="parameters" element="tns:AddProductResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="GetPrice">
    <wsdl:part name="parameters" element="tns:GetPrice">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="GetPriceResponse">
    <wsdl:part name="parameters" element="tns:GetPriceResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="AddProduct">
    <wsdl:part name="parameters" element="tns:AddProduct">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="SearchProduct">
    <wsdl:part name="parameters" element="tns:SearchProduct">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="ProductCatalog">
    <wsdl:operation name="DeleteProduct">
      <wsdl:input name="DeleteProduct" message="tns:DeleteProduct">
    </wsdl:input>
      <wsdl:output name="DeleteProductResponse" message="tns:DeleteProductResponse">
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetPrice">
      <wsdl:input name="GetPrice" message="tns:GetPrice">
    </wsdl:input>
      <wsdl:output name="GetPriceResponse" message="tns:GetPriceResponse">
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="AddProduct">
      <wsdl:input name="AddProduct" message="tns:AddProduct">
    </wsdl:input>
      <wsdl:output name="AddProductResponse" message="tns:AddProductResponse">
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="SearchProduct">
      <wsdl:input name="SearchProduct" message="tns:SearchProduct">
    </wsdl:input>
      <wsdl:output name="SearchProductResponse" message="tns:SearchProductResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="ProductCatalogServiceSoapBinding" type="tns:ProductCatalog">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="DeleteProduct">
      <soap:operation soapAction="urn:DeleteProduct" style="document"/>
      <wsdl:input name="DeleteProduct">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="DeleteProductResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetPrice">
      <soap:operation soapAction="urn:GetPrice" style="document"/>
      <wsdl:input name="GetPrice">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="GetPriceResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="AddProduct">
      <soap:operation soapAction="urn:AddProduct" style="document"/>
      <wsdl:input name="AddProduct">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="AddProductResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="SearchProduct">
      <soap:operation soapAction="urn:SearchProduct" style="document"/>
      <wsdl:input name="SearchProduct">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="SearchProductResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="ProductCatalogService">
    <wsdl:port name="ProductCatalogPort" binding="tns:ProductCatalogServiceSoapBinding">
      <soap:address location="http://localhost:8080/ProductCatalog/services"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

enter code here
jstocks
  • 11
  • 1

1 Answers1

0

Your annotation

@WebService(targetNamespace = "http://ProductCatalog.net/", portName = "ProductCatalogPort", serviceName = "ProductCatalogService")

should be

@WebService(targetNamespace = "http://ProductCatalog.net/", portName = "ProductCatalogPort", serviceName = "ProductCatalog")

Notice that serviceName = "ProductCatalogService" is changed to serviceName = "ProductCatalog"

kelmi92
  • 394
  • 2
  • 8
  • I updated the serviceName in my ProductCatalog.java file, and it throws the same exception. Do I also need to update the serviceName in the WSDL file definitions? – jstocks Oct 26 '22 at 16:04
  • The WSDL serviceName must be the same as the namespace defined in the "targetNamespace" in the wsdl:definitions tag. Take a look to this post: https://stackoverflow.com/questions/4680264/how-to-solve-serviceconstructionexception-could-not-find-definition-for-service – kelmi92 Oct 27 '22 at 06:54