Trying to get Spring component (DataSource
) autowired into JUnit ParameterResolver
. But DataSource
is not getting injected by Spring.
I have registered the SpringExtension
and also provided the context location (aaspire-test-datasource-components.xml
) to load the ApplicationContext
.
@ContextConfiguration(locations={"classpath:spring-config/aaspire-test-datasource-
components.xml"})
@ExtendWith(SpringExtension.class)
public class gdnContextResolver implements ParameterResolver
{
@Autowired
private DataSource dataSource;
@Override
public boolean supportsParameter(ParameterContext parameterContext,
ExtensionContext extensionContext) throws ParameterResolutionException {
return parameterContext.getParameter().getType() == gdnContext.class;
}
@Override
public Object resolveParameter(ParameterContext parameterContext,
ExtensionContext extensionContext) throws ParameterResolutionException {
try {
return SpringBatchJobUtil.createJobExecutionGdnContext(dataSource);
} catch (Exception e) {
throw new ParameterResolutionException(ExceptionUtil.getMessageText(e));
}
}
}