У меня есть этот тест JUnit, в котором я хочу смоделировать источник данных, который использует JNDI:
@SpringBootTest(classes = Application.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class BinCountryCheckFilterImplTest {
@MockBean
private static DataSource dataSource;
@BeforeClass
public static void setupJndi() throws Exception {
SimpleNamingContextBuilder.emptyActivatedContextBuilder();
Context context = new InitialContext();
context.bind("java:global/production", dataSource);
}
@BeforeEach
public void beforeEachTest() throws IOException {
......
}
@Test
public void testBinCountryCheckFilterImpl() throws JsonProcessingException, JAXBException {
...
}
}
Когда я запускаю оду, я получаю ошибку:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:global/production'; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or in an application resource file: java.naming.factory.initial
Failed to look up JNDI DataSource with name 'java:global/production'; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or in an application resource file: java.naming.factory.initial
Знаете ли выкак я могу решить эту проблему?