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

Spring Boot & mybatis-spring -org.apache.ibatis.type.TypeException: Could not resolve type alias #278

Closed
gituser786 opened this issue Sep 16, 2017 · 19 comments
Labels

Comments

@gituser786
Copy link

I am using spring boot 1.5.4 & mybatis-spring 1.3.0 along with mybatis-spring-boot-starter. Whenever I am running my standalone application via eclipse I am able to run. when I run the executable jar file in command line, I am getting below error.
Error creating bean with name 'classNameMapper' defined in class path resource [mybatis-context.xml]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [mybatis-context.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'class path resource [com/../..//mapper/MyMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'MyClass'. Cause: java.lang.ClassNotFoundException: Cannot find class: MyCLass


Please help me

@kazuki43zoo
Copy link
Member

Hi @gituser786 ,
Probably, this issue does not belong this project.
Could you provide small reproduce project via GitHub repository? (same with #38 (comment))

@RollsBean
Copy link

Hi gituser786,
I have a some issue like your's, have u solve this issue?
My issue is that when i use idea to run my springboot project, it's running ok but when i run with jar, it fill to run

@deoxyseia
Copy link

deoxyseia commented Nov 14, 2017

I had a similar problem. I solved it changing my XML file, specifically field resultType="MyClass" to resultType="com.my.package.entities.MyClass" and removing sessionFactory.setTypeAliasesPackage("com.my.package.entities"); for avoid to duplicate entities in Mybatis context.

@kazuki43zoo
Copy link
Member

kazuki43zoo commented Nov 15, 2017

@RollsBean and @deoxyseia , Could you provide a reproduce project on GitHub?
If you run a spring boot application using executable jar, you should be used the SpringBootVFS.
For details, please see #38.

@barrer
Copy link

barrer commented Nov 29, 2017

@kazuki43zoo @deoxyseia the answer is correct.

  1. remove sessionFactoryBean.setTypeAliasesPackage("com.your.packae.pojo")
  2. change resultType="MyClass" to resultType="com.your.packae.pojo.MyClass"
  3. repackage

@iver3on
Copy link

iver3on commented Feb 22, 2018

same problem.
I define typeAliase com.. aliase xx in mybatis-config.xml

and in application.properties mybatis.config-locations=classpath:mybatis-config.xml
why Could not resolve type alias xx???

@kazuki43zoo
Copy link
Member

@iver3on Could you provide a reproduce project via GitHub?
And I think that this issue does not belong this project. I will suggest creating a new issue on mybatis-spring-boot-starter if you cannot a resolve this issue.

@harawata harawata transferred this issue from mybatis/mybatipse Nov 5, 2018
@kazuki43zoo
Copy link
Member

@gituser786 @RollsBean @deoxyseia @iver3on

This issue transferred from mybatis/mybatipse project. Could you feedback for this issue? (Could provide a small reproduce project?)
If not feedback, I will close this issue.

@kazuki43zoo
Copy link
Member

@gituser786 @RollsBean @deoxyseia @iver3on

I've closed this issue because no feedback.
If there is problem, please reopen this.

@chris-peng-1244
Copy link

I just created a mini project that reproduces a similar issue. Here is the git repo. https://github.com/chris-peng-1244/ibatis-resolve-type-alias

The project works fine in IntelliJ, but if I execute java -jar xxxx.jar it complained that BookDO couldn't be resolved.

The reason that this project followed some very unorthorgnal file structures and naming conventions is that:

  1. The real project has 4 data sources that need configuration
  2. It was developed in Spring 4 originally.
  3. I tried to port it to Spring boot 2.1

Hope the demo helps clarify the problems a little better.

@kazuki43zoo
Copy link
Member

@chris-peng-1244

Please use the SpringBootVFS as follow:

SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setVfs(SpringBootVFS.class);
// ...

@chris-peng-1244
Copy link

@kazuki43zoo It works, thank you so much!

@doannguyenminhchi
Copy link

doannguyenminhchi commented Jul 6, 2019

Thank @kazuki43zoo

@adrixgc
Copy link

adrixgc commented Sep 11, 2019

Thanks @kazuki43zoo, could you please elaborate why this is the solution? Couldn't find any documentation about it

@kazuki43zoo
Copy link
Member

@ghost
Copy link

ghost commented Nov 14, 2019

@adrixgc Please see http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/#Using_the_SpringBootVFS. Is OK?

nothing changes..
spring boot can not find type alias but complete class name with package..

@ghost
Copy link

ghost commented Nov 14, 2019

@adrixgc Please see http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/#Using_the_SpringBootVFS. Is OK?

nothing changes..
spring boot can not find type alias but complete class name with package..

oh! it works.
i just put the package location in setTypeAliasesPackage method,
not just in setTypeAliasesPackage method.

@tinarooot
Copy link

已经指定包名,全名称了
为什么还是会报错

<update id="updateGenTableColumn" parameterType="com.cainaer.gen.domain.GenTableColumn">

Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'GenTableColumn'. Cause: java.lang.ClassNotFoundException: Cannot find class: GenTableColumn

@kazuki43zoo
Copy link
Member

@xiao-ma-nong

This issue is closed already. If you have a problem, please create a new issue with reproduce project via GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants