Hi All
I’m trying to execute a Junit test in a Spring boot application, the Junit should test some CRUD operations, I’m using Spring Repositories specifically JpaRepository.
The Repository calss:
package au.com.bla.bla.bla.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import au.com.bla.bla.bla.entity.Todo;
public interface TodoRepository extends JpaRepository<Todo, Integer> {
}
TodoController class
package au.com.bla.bla.bla.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import au.com.bla.bla.bla.entity.Todo;
import au.com.bla.bla.bla.repository.TodoRepository;
import java.util.List;
import java.util.Map;
#RestController
#CrossOrigin
public class TodoController
{
static final String TEXT = "text";
#Autowired
private TodoRepository todoRepository;
...
#RequestMapping(path = "/todo", method = RequestMethod.POST)
public Todo create(#RequestBody Map<String, Object> body)
{
Todo todo = new Todo();
todo.setCompleted(Boolean.FALSE);
todo.setText(body.get(TEXT).toString());
todoRepository.save(todo);
return todo;
}
...
The JUnit:
package au.com.bla.bla.bla.controller;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import au.com.bla.bla.bla.repository.TodoRepository;
#WebMvcTest(TodoController.class)
#RunWith(SpringRunner.class)
public class TodoControllerTest {
#Autowired
private MockMvc mvc;
#Autowired
private TodoController subject;
#Before
public void setUp() {
}
#Test
public void testCreate() throws Exception {
String json = "{\"text\":\"a new todo\"}";
mvc.perform(post("/todo").content(json)
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(3))
.andExpect(jsonPath("$.text").value("a new todo"))
.andExpect(jsonPath("$.completed").value(false));
assertThat(subject.getTodos()).hasSize(4);
}
...
Problem:
When executing the Junit I end up with this exception:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'todoController': Unsatisfied dependency expressed through field 'todoRepository': No qualifying bean of type [au.com.bla.bla.bla.repository.TodoRepository] found for dependency [au.com.bla.bla.bla.repository.TodoRepository]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [au.com.bla.bla.bla.repository.TodoRepository] found for dependency [au.com.bla.bla.bla.repository.TodoRepository]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
…
Can anyone help with this ?
Thanks in advance
Your error is actually the expected behavior of #WebMvcTest.
You basically have 2 options to perform tests on your controller.
1. #WebMvcTest - need to use #MockBean
With #WebMvcTest, a minimal spring context is loaded, just enough to test the web controllers. This means that your Repository isn't available for injection:
Spring documentation:
#WebMvcTest will auto-configure the Spring MVC infrastructure and
limit scanned beans to #Controller, #ControllerAdvice, #JsonComponent,
Filter, WebMvcConfigurer and HandlerMethodArgumentResolver.
Assuming the goal is just to test the Controller, you should inject your repository as a mock using #MockBean.
You could have something like:
#RunWith(SpringRunner.class)
#WebMvcTest(TodoController.class)
public class TodoControllerTest {
#Autowired
private MockMvc mvc;
#Autowired
private TodoController subject;
#MockBean
private TodoRepository todoRepository;
#Test
public void testCreate() throws Exception {
String json = "{\"text\":\"a new todo\"}";
mvc.perform(post("/todo").content(json)
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(3))
.andExpect(jsonPath("$.text").value("a new todo"))
.andExpect(jsonPath("$.completed").value(false));
Mockito.verify(todoRepository, Mockito.times(1)).save(any(Todo.class));
}
}
2. #SpringBootTest - you can #Autowire beans
If you want to load the whole application context, then use #SpringBootTest: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html
You'd have something like this:
#RunWith(SpringRunner.class)
#SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class TodoControllerTest {
private MockMvc mvc;
#Autowired
TodoController subject;
#Autowired
private WebApplicationContext context;
#Before
public void setup() {
this.mvc = MockMvcBuilders.webAppContextSetup(context).build();
}
#Test
public void testNoErrorSanityCheck() throws Exception {
String json = "{\"text\":\"a new todo\"}";
mvc.perform(post("/todo").content(json)
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(3))
.andExpect(jsonPath("$.text").value("a new todo"))
.andExpect(jsonPath("$.completed").value(false));
assertThat(subject.getTodos()).hasSize(4);
}
}
Related
I'm learning Spring: I've a simple JUnit test based on Spring, but I can't understand why one test is failing and the other not, since I'm expecting the #Autowired annotation to work in both of them
I have 2 classes:
package it.euphoria.data.service;
import it.euphoria.data.entity.Customer;
import it.euphoria.data.entity.Seller;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import javax.validation.constraints.NotNull;
import java.util.Set;
public interface CustomerRepository extends JpaRepository<Customer, Long> {
#Query("SELECT cust FROM Customer cust WHERE cust.seller = :seller")
Set<Customer> getBySeller(#NotNull #Param("seller") Seller seller);
}
and a Service class:
package it.euphoria.data.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
#Service
public class CustomerService {
private CustomerRepository customerRepository;
#Autowired
public CustomerService(CustomerRepository customerRepository) {
this.customerRepository = customerRepository;
}
public CustomerRepository getCustomerRepository() {
return customerRepository;
}
}
If , while testing, I autowire CustomerRepository it works fine, but if I autowire CustomerService I get an UnsatisfiedDependencyException
This is the working test with CustomerRepository:
package it.euphoria.data.service;
import it.euphoria.data.entity.Customer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit4.SpringRunner;
#RunWith(SpringRunner.class)
#DataJpaTest
public class CustomerRepositoryTest {
#Autowired
CustomerRepository customerRepository;
#Test
public void getBySeller() {
//test things...
}
}
And this is the broken one with CustomerService as only difference:
package it.euphoria.data.service;
import it.euphoria.data.entity.Customer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit4.SpringRunner;
#RunWith(SpringRunner.class)
#DataJpaTest
public class CustomerRepositoryTest {
#Autowired
CustomerService customerService; //<-- The error is here
#Test
public void getBySeller() {
//test things...
}
}
This is the stacktrace:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name
'it.euphoria.data.service.CustomerRepositoryTest': Unsatisfied
dependency expressed through field 'customerService'; nested exception
is org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type 'it.euphoria.data.service.CustomerService'
available: expected at least 1 bean which qualifies as autowire
candidate. Dependency annotations:
{#org.springframework.beans.factory.annotation.Autowired(required=true)}
I've found this question and answer , but it didn't solve the problem.
Could you please help me understanding what I'm doing wrong here?
#DataJpaTest loads the beans which are relevant to the work with the database, read Repositories and more low level stuff (DataSources, Transaction manager, etc).
These tests are used to check the correctness of your SQL queries and any code that resides in the DAO.
It doesn't load the whole application in any case but only a certain part of it.
Now the service is a place where you usually write a business logic and it doesn't interact with database directly (only via DAOs, repositories, etc.)
So spring doesn't load services in #DataJpaTest
I have a project with a small AspectJ class:
package com.blabla.joy.aspect;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
#Aspect
#Component
public class SomeAspect {
public SomeAspect() {
}
}
also there is a small test class:
package com.blabla.joy.aspect;
import com.blabla.joy.MainSpringBoot;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
#RunWith(SpringRunner.class)
#SpringBootTest
#ContextConfiguration(classes = {MainSpringBoot.class})
public class SomeTest {
#MockBean
private SomeAspect someAspect;
#Test
public void someTest(){
//test something
}
}
The main application class is:
package com.blabla.joy;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
#SpringBootApplication(exclude = MultipartAutoConfiguration.class)
#EnableAspectJAutoProxy(proxyTargetClass = true)
public class MainSpringBoot implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(MainSpringBoot.class, args);
}
#Override
public void run(String... arg0) throws Exception {
System.out.println("i'm running!!!");
}
}
When i run SomeTest the following error occures:
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainSpringBoot': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: [com.blabla.joy.aspect.SomeAspect$MockitoMock$2005048991] cannot extend concrete aspect [com.blabla.joy.aspect.SomeAspect]
...
Caused by: org.springframework.aop.framework.AopConfigException: [com.blabla.joy.aspect.SomeAspect$MockitoMock$2005048991] cannot extend concrete aspect [com.blabla.joy.aspect.SomeAspect]
...
What does it mean? Should i add some special logic (annotations, etc.) to my aspect, test or main class?
P.S: i use SpringBoot2 in the project
Try this:
#RunWith(SpringRunner.class)
#SpringBootTest
#ContextConfiguration(classes = {MainSpringBoot.class})
public class SomeTest {
#Autowired
#InjectMocks
private SomeAspect someAspect;
#Before
public void init(){
MockitoAnnotations.initMocks(this)
}
#Test
public void someTest(){
//test something
}
}
I am running through the tutorial.example on https://developer.ibm.com/tutorials/spring-with-db2-via-jdbc/
but cannot get it to work, i keep getting the below error and am unsure how to fix.
No qualifying bean of type 'org.springframework.jdbc.core.JdbcTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}'
Nothing to do with setting up a bean is mentioned in the tutorial so am unsure if i should be breaking off it to fix it or i've just made a mistake.
my application class -
#SpringBootApplication
public class SBApplication {
public static void main(String[] args) {
SpringApplication.run(SBApplication.class, args);
}
}
Example rest controller -
package application.rest.v1;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.List;
import main.java.application.jdbc.*;
#RestController
public class Example {
#Autowired
JdbcTemplate jdbcTemplate;
#RequestMapping("test")
public #ResponseBody ResponseEntity<String> example() {
List<String> list = new ArrayList<>();
list.add("Table data...");
jdbcTemplate.query(
"SELECT * FROM things", new Object[]{},
(rs,rowNum) -> new Things(rs.getLong("id"), rs.getString("name")))
.forEach(thing -> list.add(thing.toString()));
return new ResponseEntity<String>(list.toString(), HttpStatus.OK);
}
}
application.properties -
spring.datasource.url=jdbc:imdb://xxxx.xxx.xxxx/xxxx
spring.datasource.username=xxxxxxx
spring.datasource.password=xxxx
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Also, i am not connecting to the suggested DB2 instance in the tutorial but my own instance.
I believe you are missing the part where you are supposed to configure JdbcTemplate in your configuration. As you are using spring boot, you can achieve it through #Configuration annotation on a class. You typical configuration will look something like below
#Configuration
public class WebAppConfig {
#Bean(name = "appDataSource")
#Primary
#ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
#Bean(name = "applicationJdbcTemplate")
public JdbcTemplate applicationDataConnection(){
return new JdbcTemplate(dataSource());
}
}
I am using Spring + Mysql and I can Autowire successfully my classes that extended from PagingAndSortingRepository<T,E> in my RepositoryRestController class.
I can autowire the my repositories in controller below.
package com.fallavi.api.user.controller;
import com.fallavi.api.MyConfig;
import com.fallavi.api.purchase.model.Purchase;
import com.fallavi.api.purchase.repository.PurchaseRepository;
import com.fallavi.api.reader.model.Reader;
import com.fallavi.api.reader.repository.ReaderRepository;
import com.fallavi.api.user.calculator.UserCreditHelper;
import com.fallavi.api.user.exceptions.UserCanNotFindException;
import com.fallavi.api.user.model.UserCreditEnoughModel;
import com.fallavi.api.user.model.UserCreditModel;
import com.fallavi.api.user.repository.UsersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
#RepositoryRestController
#RequestMapping("/user")
public class UserCreditController {
#Autowired
private ReaderRepository readerRepository;
#Autowired
private UsersRepository usersRepository;
#Autowired
private PurchaseRepository purchaseRepository;
#GetMapping(
value = "/userHasCreditEnough/{reader_id}",
headers = "Content-Type=application/json")
public ResponseEntity<UserCreditEnoughModel> userHasCreditEnough(
#RequestHeader(value = "Authorization") String token,
#PathVariable Long reader_id) {
UserCreditHelper userCreditHelper = new UserCreditHelper();
// Find user ID from authorization code START //
Long userID = usersRepository.getUserIDByAuthToken(token);
if (userID == null) {
throw new UserCanNotFindException();
}
// Find user ID from authorization code END //
// Find user credit START //
List<Purchase> purchaseList = this.purchaseRepository.findByUserID(userID);
Integer userCreditLeft = userCreditHelper.userCreditLeft(purchaseList);
// Find user credit END //
// Find user's credit left for Reader START //
Reader reader = this.readerRepository.findByReaderID(reader_id);
boolean isUserCreditEnough = userCreditHelper.userHasCreditEnough(userCreditLeft, reader);
// Find user's credit left for Reader END //
return ResponseEntity.ok(new UserCreditEnoughModel(isUserCreditEnough, reader.getOnline()));
}
}
Sure I want to seperate all layers as service, repository and Controller it is why I creating a new helper class that is service layer.
#Service
public class UserCreditHelper {
#Autowired
UsersRepository usersRepository;
....some methods...
}
In order to call UserCreditHelper class in I am using ApplicationContext in my controller class sample below.
#RepositoryRestController
#RequestMapping("/user")
public class UserCreditController {
#Autowired
private ReaderRepository readerRepository;
#Autowired
private UsersRepository usersRepository;
#Autowired
private PurchaseRepository purchaseRepository;
#GetMapping(
value = "/userHasCreditEnough/{reader_id}",
headers = "Content-Type=application/json")
public ResponseEntity<String> userHasCreditEnough(
#RequestHeader(value = "Authorization") String token) {
// com.fallavi.api.user.calculator is the package of UserCreditHelper.
ApplicationContext ctx = new AnnotationConfigApplicationContext( "com.fallavi.api.user.calculator" );
return ResponseEntity.ok("test");
}
}
When I tried to request /userHasCreditEnough/{reader_id} endpoint it gives error alltime.
"Error creating bean with name 'userCreditHelper': Unsatisfied dependency expressed through field 'usersRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.fallavi.api.user.repository.UsersRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}",
You should create an interface which will be your service layer. Then inject that interface into the controller and call the desire methods in the desire end point of the controller. From there call the implantation you want from this injected interface.
I have the following configuration class:
#Configuration
public class StartupConfig {
private final Logger log = LoggerFactory.getLogger(this.getClass().getSimpleName());
#PostConstruct
public void init() {
log.debug("Start up config initialized.");
}
#Bean
public SchedulerService schedulerService() {
return new SchedulerService();
}
}
I want to be able to load the schedulerService bean from the applications main method. Something like this:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.crm.config.StartupConfig;
import com.crm.service.SchedulerService;
#SpringBootApplication
#EnableCaching
public class Server {
public static void main(String[] args) throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(StartupConfig.class);
context.refresh();
SpringApplication.run(Server.class, args);
SchedulerService schedulerService = (SchedulerService) context.getBean("schedulerService");
schedulerService.start();
}
}
The schedulerService class has an Autowired dependency:
#Service
#Transactional
public class SchedulerService {
#Autowired
private SchedulerTriggerJpaDao schedulerTriggerJpaDao;
...
Here is the definition of SchedulerTriggerJpaDao:
package com.crm.dao;
import java.util.Collection;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import com.crm.entity.SchedulerTrigger;
#Transactional
public interface SchedulerTriggerJpaDao extends JpaRepository<SchedulerTrigger, Integer> {
public Collection<SchedulerTrigger> findByEnabledTrueAndDeletedFalse();
}
When I run up the application I get the following error:
Exception in thread "main"
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'schedulerService': Unsatisfied
dependency expressed through field 'schedulerTriggerJpaDao'; nested
exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type 'com.crm.dao.SchedulerTriggerJpaDao'
available: expected at least 1 bean which qualifies as autowire
candidate. Dependency annotations:
{#org.springframework.beans.factory.annotation.Autowired(required=true)}
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
at
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
What do I need to change to correctly initialise the schedulerService bean so it can also initialise the schedulerTriggerJpaDao dependency?
If your SchedulerTriggerJpaDao class has the following annotation
#Repository
then it should be recognised as a bean.
Your SchedulerTriggerJpaDao is just an interface. You need
either provide a Dao implementation yourself and annotate it with #Component
(FYI #Repository and #Service automatically mark class as component)
or use some framework that will generate a Dao implementation for you based on your interface. E.g. Spring Data JPA (http://projects.spring.io/spring-data-jpa/)
The problem is that you are returning a new instance of the SchedulerService, which is not managed by spring. You are annotating the class as a #Service but spring is only managing the one injected by #Inject and/or #Autowire.