|
25 | 25 | import org.springframework.data.jdbc.mybatis.MyBatisDataAccessStrategy;
|
26 | 26 | import org.springframework.data.repository.CrudRepository;
|
27 | 27 | import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
| 28 | +import org.springframework.instrument.classloading.ShadowingClassLoader; |
28 | 29 | import org.springframework.jdbc.core.JdbcOperations;
|
29 | 30 | import org.springframework.jdbc.core.JdbcTemplate;
|
30 | 31 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
| 32 | +import org.springframework.util.ReflectionUtils; |
31 | 33 |
|
32 | 34 | /**
|
33 | 35 | * Tests the dependency injection for {@link JdbcRepositoryFactoryBean}.
|
@@ -211,6 +213,29 @@ public void withSqlSessionFactoryThereIsMyBatisIntegration() {
|
211 | 213 | assertThat(findDataAccessStrategy(factory, MyBatisDataAccessStrategy.class)).isNotNull();
|
212 | 214 | }
|
213 | 215 |
|
| 216 | + @Test // DATAJDBC-136 |
| 217 | + public void canBeLoadedWithoutMyBatis() throws Exception { |
| 218 | + |
| 219 | + String sqlSessionFactoryClassName = SqlSessionFactory.class.getName(); |
| 220 | + |
| 221 | + ShadowingClassLoader classLoader = new ShadowingClassLoader(this.getClass().getClassLoader()) { |
| 222 | + |
| 223 | + @Override |
| 224 | + public Class<?> loadClass(String name) throws ClassNotFoundException { |
| 225 | + |
| 226 | + if (name.equals(sqlSessionFactoryClassName)) { |
| 227 | + throw new ClassNotFoundException("%s is configured not to get loaded by this classloader"); |
| 228 | + } |
| 229 | + return super.loadClass(name); |
| 230 | + } |
| 231 | + }; |
| 232 | + |
| 233 | + Class<?> loadedClass = classLoader.loadClass(JdbcRepositoryFactoryBean.class.getName()); |
| 234 | + |
| 235 | + assertThat(loadedClass).isNotNull(); |
| 236 | + ReflectionUtils.getAllDeclaredMethods(loadedClass); |
| 237 | + } |
| 238 | + |
214 | 239 | private Condition<? super RepositoryFactorySupport> using(NamedParameterJdbcOperations expectedOperations) {
|
215 | 240 |
|
216 | 241 | Predicate<RepositoryFactorySupport> predicate = r -> extractNamedParameterJdbcOperations(r) == expectedOperations;
|
|
0 commit comments