Skip to content

SqlSessionFactoryBean single resource, using wildcard causes a IOException #792

Open
@JuHyun419

Description

@JuHyun419

image

I saw the setMapperLocations method comment in the SqlSessionFactoryBean class and set up Resource using wildcard, but the following exception occurred:

java.io.IOException: Failed to parse mapping resource: 'class path resource'

image


If you use the getResource() method that returns a single resource, an exception occurs when using wildcards.

The relevant test codes are as follows:
(I added this test code to the SqlSessionFactoryBeanTest class)

  @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());
  }

image


If you use `getResources()`, there are no exceptions when you use wildcard.
  @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());
  }

image

So, Why don't you add a description of this exception information in the comments of the setMapperLocations method?
And is it okay to add this test code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions