1

I am new in the spring/boot word and have a working JAX-WS based web-service declared in a springboot project. It is started and configured via web.xml and sun-jaxws.xml. So, no beans included there only endpoints declarations and servlet definitions and mappings. I just now want to save the items i get in the webservice into the mysql database using spring-boot-starter-jdbc which is not working: I can't achieve this as the repository is not injected in the webservice implementation.

Followed all steps in other question, but not achieving this! Normally declaration of the datasource parameters in application.properties and annotating @webservice and @Repository would suffice to get the injection of the repository working in the webservice class. What am i missing ?

Here details of the steps I followed: the webservice implementation is a package X and i created a @SpringBootApplication in order to use a mysql datasource declared in application.properties. So i annotated the webservice as a @Component and the data access repository with @Repository and @Component

parent version: spring-boot-starter-parent : 1.5.10.RELEASE

webservice service implementation: BServiceManager.java

    package X;
    ....
    @Component
    @WebService(name = "***",***)
    @BindingType("http://schemas.xmlsoap.org/wsdl/soap/http")
    @XmlSeeAlso({
        packagesxxx.class,
        ....
        })
    public class BServiceManager
        implements xxxxx
        {
         ....
         @Autowired    
         private ItemRepository irepo;
         
         ....
         @WebMethod(**)
         @WebResult(***)
         public ResponseDataInfo sendInfo( ){
         ....
         trepo.saveitem(item)
         ....         
         }
    }

ItemRepository.java

    package Y.Z;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.dao.DataAccessException;
    import org.springframework.stereotype.Component;
    import org.springframework.stereotype.Repository;

    @Component
    @Repository
    public class ItemRepository {
    
        @Autowired
        private JdbcTemplate jdbcTemplate ;
        
        ....
        public boolean saveitem(Item item) {
        
        ....
        }
    
    
     }

Item.java

    package Y.Z;
    public class Item {
        ....
    }

GetItemsApplication

    package Y;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.ComponentScan;
    
    //@ComponentScan(basePackages={"Y","Y.Z","X"})
    @SpringBootApplication
    public class GetItemsApplication   {
        ....
        public static void main(String[] args) {
            SpringApplication.run(GetItemsApplication.class, args);
            log.info("--Spring Boot inits done--");
        }
        
    }

application.properties

    spring.data.jpa.repositories.enabled=false
    spring.data.jdbc.repositories.enabled=true

    # MySQL properties
    spring.datasource.url=****
    spring.datasource.username=****
    spring.datasource.password=****
    ....
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    logging.level.org.springframework.jdbc.core.JdbcTemplate=debug

NB: even having datasource bean is not helping :

    File: DataSourceConfig.java

    package Y.Z;
    import javax.sql.DataSource;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.jdbc.core.JdbcTemplate;
    //@EnableJdbcRepositories for Spring

    @Configuration
    public class MDataSourceConfig {
        
        @Bean
        public DataSource dataSource() {
            DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
            return dataSourceBuilder.build();      
        }

        @Bean
        public JdbcTemplate getJdbcTemplate() {
           return new JdbcTemplate(dataSource());
        }            
    }
jayFifth
  • 11
  • 3
  • You can read some relevant Q/A here: https://stackoverflow.com/questions/25177491/spring-boot-register-jax-ws-webservice-as-bean – pleft Aug 29 '21 at 14:08
  • 1
    @pleft thanks for info. now i know it couldn't succeed as such. – jayFifth Aug 29 '21 at 16:40
  • @pleft Again many thanks. I finally get it working using the registration of the webservice in a CXF Servlet as suggested by jonashackt in your link. – jayFifth Aug 30 '21 at 21:09
  • So, principle here is to get rid of web.xml and sun-jaxws.xml and wrap the webservice in a CXFServlet bean, as described by @jonashackt on the link pleft provided: https://stackoverflow.com/questions/25177491/spring-boot-register-jax-ws-webservice-as-bean – jayFifth Aug 30 '21 at 21:26

1 Answers1

0

Your Webservice doesn't seem to get created by Spring. Therefore Spring has no control over its dependencies, so you have to get the dependency programmatically.

There are many ways to do this.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • Jens, thanks for your reply. I finally get it working wrapping the webservice created by JaxWs in a CXF servlet as suggested by the link sent by pleft above – jayFifth Aug 30 '21 at 21:12