我在自动接线字段上遇到以下错误。我已在xml文件中添加了扫描标签,但仍然无法使用。我使用的是Spring 5.1.6.RELEASE版本
<context:component-scan base-package="com.app.service">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Service" />
</context:component-scan>
Error:
Unsatisfied dependency expressed through field 'approveTimesheetService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.app.service.ApproveTimesheetService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
24-Apr-2019 15:01:13 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
24-Apr-2019 15:01:13 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
24-Apr-2019 15:01:13 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374)
24-Apr-2019 15:01:13 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411)
24-Apr-2019 15:01:13 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:391)
24-Apr-2019 15:01:13 at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:119)
24-Apr-2019 15:01:13 `enter code here`at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
24-Apr-2019 15:01:13 at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
24-Apr-2019 15:01:13 at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.
遇到错误的类
@TestMethodOrder(OrderAnnotation.class)
@SpringJUnitWebConfig(locations = { "classpath*: service.xml", "classpath*:data.xml" })
@TestInstance(Lifecycle.PER_CLASS)
@Retention(RetentionPolicy.RUNTIME)
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestLeaveHourCal_moes18 {
@Autowired
private ApproveTimesheetService approveTimesheetService; //error on this
@Autowired
private ComparePayUpdates comparePayUpdates;
@Autowired
public TestClassSettings testClassSettings; /* variable access type needs public */;
@Autowired
@RegisterExtension
protected CreateTimesheetBeforeTestExecutionCallback beforeTestExecutionCallback; /* can not be private */
@BeforeAll
public void setup() throws Exception {
/* START SETTINGS */
testClassSettings.setTestIndicator("18");
testClassSettings.setTitleUnitCode("99");
}}
服务注释已添加到ApproveTimesheetService类。
@Service("approveTimesheetService")
public class ApproveTimesheetServiceImpl implements ApproveTimesheetService, Serializable {
protected static final Logger LOG = LoggerFactory.getLogger(ApproveTimesheetServiceImpl.class);
protected final static String TS_QUOTE = "'";
}
Any
建议?
我的servic.xml和data.xml在web-inf / config文件夹中。 Service.xml具有上下文扫描标记。 我的课程在web-inf / classes文件夹中。我认为TestLeaveHourCal_moes18无法找到service.xml。可能是我没有正确设置@SpringJUnitWebConfig标记。我尝试了“ classpath”,但也没有用。
答案 0 :(得分:0)
我能够通过在pom.xml中添加以下内容来解决此问题,以进行maven sure fire plugin配置会话。看起来它需要xml文件(service.xml)所在的路径。
sdk-tools-linux-4333796.zip