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());
}
}