java - Spring doesn't instantiate bean at start -


i'm stuck following problem. application doesn't create services @ startup , end nullpointerexception when try use them in maven tests after inject them @autowired.

i don't understand comes from. have done research still don't understand why doesn't work.

here class autowired administrationactionservice null:

public class administrationactiontests extends entitytests {      @autowired     administrationactionservice administrationactionservice;      @test     public void equalstests() {          administrationactionservice.getexample();          [...] 

the class :

package com.bloombooking.services; @org.springframework.stereotype.service public class administrationactionservice extends serviceentity{      @autowired private administrationactiondao administrationactiondao;      [...] 

and applicationcontext.xml. i've placed in src/applicationcontext.xml

<?xml version="1.0" encoding="utf-8"?>  <beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        xmlns:context="http://www.springframework.org/schema/context"        xsi:schemalocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-3.0.xsd">      <context:component-scan base-package="com.bloombooking.services, com.bloombooking.dao"/>  </beans> 

i don't know have done wrong. can me? thanks!

to make work have make following changes:

  1. add @runwith(springjunit4classrunner.class) class.
  2. add @contextconfiguration("path_to_you_spring_beans.xml")

so class becomes:

@runwith(springjunit4classrunner.class) @contextconfiguration("path_to_you_spring_beans.xml") administrationactiontests { } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -