spring icon indicating copy to clipboard operation
spring copied to clipboard

SqlSessionFactoryBean single resource, using wildcard causes a IOException

Open JuHyun419 opened this issue 1 year ago • 4 comments

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?

JuHyun419 avatar Mar 17 '23 06:03 JuHyun419

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

sarswat001 avatar Apr 15 '23 11:04 sarswat001

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

hazendaz avatar Apr 15 '23 18:04 hazendaz

Hi, Will this not get merged?

sarswat001 avatar Apr 22 '23 12:04 sarswat001

Based on the stack the actual error is not on the setter, it's elsewhere so any adjustment would need done where it occurs, and I was thinking you intended to enhance the message not simply add a javadoc.

Where you put that currently violates javadocs linter. The setter does not throw anything nor would it as that violates bean spec. Please look to where issue actually pops and provide a better exception that will help users. Most would not read a stack and think javadocs would tell them how to solve. The stack message should tell them.

Sent from my Verizon, Samsung Galaxy smartphone Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Sarswat Aryan @.> Sent: Saturday, April 22, 2023 8:46:56 AM To: mybatis/spring @.> Cc: Jeremy Landis @.>; Comment @.> Subject: Re: [mybatis/spring] SqlSessionFactoryBean single resource, using wildcard causes a IOException (Issue #792)

Hi, Will this not get merged?

— Reply to this email directly, view it on GitHubhttps://github.com/mybatis/spring/issues/792#issuecomment-1518641988, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAHODIZBDXA7KF2N5VB62UDXCPHMBANCNFSM6AAAAAAV6EJ36A. You are receiving this because you commented.Message ID: @.***>

hazendaz avatar Apr 22 '23 18:04 hazendaz