服务类的注入属性为null,但对于另一个类

时间:2017-10-29 20:19:32

标签: java spring hibernate jpa spring-annotations

我坚持这个,让我们说,在PMTest中,testConfig方法, 注入时,geoService将GeoRep属性设置为null,但PMTest类的GeoRep属性不为null。为什么会这样?

这是我的课程

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {PersistenceConfig.class})

public class PMTest {

@Autowired
private GeoRep geoRep;

@Autowired
private GeoService geoService;

@Test
public void testConfig() {
        geoServive.findAll();
        geoRep.findAll();

    }

}



@Service
public class GeoService {

    @Autowired
    private GeoRep geoRep;
    .
    .
    .
}



@Transactional
public interface GeoRep extends JpaRepository<GeoRegion, Long> {

}

任何帮助,谢谢。

简而言之,

PMTest
  -
  - - - - - - GeoService
  -               -
  -               -
  -               - - - - - - GeoRep (is null)
  -          
  -
  -
  - - - - - - - GeoRep (is not null)

0 个答案:

没有答案
相关问题