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?

Activity

sarswat001

sarswat001 commented on Apr 15, 2023

@sarswat001

Hi,
Task here is to add comment for setMapperLocations() and also add JUnits for this?

hazendaz

hazendaz commented on Apr 15, 2023

@hazendaz
Member

Hi @sarswat001, sounds reasonable to assist users, feel free to raise PR for same and we can take a look at it. Thanks.

sarswat001

sarswat001 commented on Apr 22, 2023

@sarswat001

Hi,
Will this not get merged?

hazendaz

hazendaz commented on Apr 22, 2023

@hazendaz
Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @hazendaz@JuHyun419@sarswat001

      Issue actions

        SqlSessionFactoryBean single resource, using wildcard causes a IOException · Issue #792 · mybatis/spring