Bonsoir,
je suis débutante en spring , j'ai suivi un tutorial et je voulais tester si tout va bien, mais lors de la compilation de JUnit de ma classe test j'ai l'erreur suivante qui s'affiche :
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'profilService' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:378)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1012)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:227)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:888)
at ma.tgr.gestionExigences.parametrage.service.ProfilServiceTest.setUpBeforeClass(ProfilServiceTest.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
sachant que j'ai utilisé les annotations pour déclarer mon service :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
 
@Service("profilService")
@Transactional
public class ProfilServiceImpl implements ProfilService {
 
	@Autowired
	private SessionFactory sessionFactory;
 
 
	@Override
	@SuppressWarnings("unchecked")
	public List<Profil> findAll() {
		// TODO Auto-generated method stub
		return sessionFactory.getCurrentSession().createQuery("from profil").list();
	}
 
	@Override
	public Profil findById(Integer id) {
		// TODO Auto-generated method stub
		return (Profil) sessionFactory.getCurrentSession().load(Profil.class, id);
	}
 
	@Override
	public void save(Profil profil) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().saveOrUpdate(profil);
 
	}
 
}
la classe du test
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
 
import static org.junit.Assert.*;
 
import java.util.List;
 
 
 
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
 
public class ProfilServiceTest {
 
	private static ClassPathXmlApplicationContext context;
	private static ProfilService profilService;
 
 
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		context = new ClassPathXmlApplicationContext("application-context.xml");
		profilService = (ProfilService) context.getBean("profilService");
 
	}
 
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		context.close();
	}
 
	@Test
	public void testFindAll() {
 
		fail("Not yet implemented");
	}
 
	@Test
	public void testFindById() {
		fail("Not yet implemented");
	}
 
	@Test
	public void testSave() {
		fail("Not yet implemented");
	}
 
}
si quelqu'un peut m'aider car j'ai cherché un peu sur internet mais j'ai pas trouvé une solution, merci d'avance