Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

792:adding Exception description for setMapperLocations() method #802

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ public void setConfiguration(Configuration configuration) {
*
* @param mapperLocations
* location of MyBatis mapper files
* @throws IOException
* in case of I/O errors.
* Class.getResource() returns null when trying to get mapperLocations from newly generated files or JAR files,
* ClassLoader.getResources() is advisable.
*/
public void setMapperLocations(Resource... mapperLocations) {
this.mapperLocations = mapperLocations;
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.mockrunner.mock.jdbc.MockDataSource;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Properties;
Expand Down Expand Up @@ -53,6 +54,8 @@
import org.mybatis.spring.type.SuperType;
import org.mybatis.spring.type.TypeHandlerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

class SqlSessionFactoryBeanTest {

Expand Down Expand Up @@ -335,6 +338,30 @@ void testMapperLocationsWithNullEntry() throws Exception {
assertDefaultConfig(factoryBean.getObject());
}

@Test
void testSingleResourceWildcardMapperLocationsShouldThrowException() {
setupFactoryBean();

PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource resource = resolver.getResource("classpath*:org/mybatis/spring/*Mapper.xml");

factoryBean.setMapperLocations(resource);

assertThrows(IOException.class, () -> factoryBean.getObject());
}

@Test
void testMultiResourceMapperLocations() throws Exception {
setupFactoryBean();

PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resource = resolver.getResources("classpath*:org/mybatis/spring/*Mapper.xml");

factoryBean.setMapperLocations(resource);

assertNotNull(factoryBean.getObject());
}

@Test
void testAddATypeHandler() throws Exception {
setupFactoryBean();
Expand Down