Ich bin der nächste Test ausgeführt wird:Frühling @ContextConfiguration
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/META-INF/spring/applicationContext.xml" })
public class FloorServiceTest {
@Autowired
private FloorService floorService;
@Test
public void testFloorService() {
floorService.findById((long)1);
}
}
Mit der Datei applicationContext.xml
unter dem Ordner /APP/src/main/resources/META-INF/spring/
Aber es scheint nicht richtig die Bohne Autowire:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.confloorapp.services.FloorServiceTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.confloorapp.services.FloorService com.confloorapp.services.FloorServiceTest.floorService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.confloorapp.services.FloorService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Diesen Anwendungskontext posten? – chrylis
Könnten Sie bitte Ihre ApplicationContext-Datei veröffentlichen. Probieren Sie 'ApplicationContext context = new ClassPathXmlApplicationContext (" Klassenpfad: /META-INF/spring/applicationContext.xml ");' innerhalb Ihrer Klasse, das könnte funktionieren –
Können Sie versuchen mit: @ContextConfiguration (locations = {"classpath: /applicationContext.xml "}) – Arpit