Place MyBatis Main Config file under src/main/resources

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Place MyBatis Main Config file under src/main/resources

Vladimir Alarcon
Hi,

Is it possible to place the MyBatis Main Config file
("mybatis-config.xml") file inside src/main/resources ?

I have a Spring Boot project. I'm using MyBatis XML mappers and they
are located under src/main/resources. Good.

However, the main MyBatis XML config file needs to be placed under
src/main/webapp; if I place it under src/main/resources MyBatis does
not find it. This has also the undesired side effect that it becomes
available as a web resource. For example, this shouldn't work but it
does:

  $ wget localhost:8080/mybatis-config.xml

This is how I configured it:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="configLocation" value="mybatis-config.xml" />
  <property name="objectFactory" ref="springBeanObjectFactory" />
</bean>

I'm using this configuration to set the "objectFactory" and read VOs
as Spring Beans.

Do you know any way to place it unser src/main/resources? A solution
using Java annotations is also welcome, but I haven't been able to
make it work.

Thank you,
Vlad

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CAP3Y0Vb3CwjxFcigbufw-4vzSG-DH_UeoF0NhuniQ2UPEgHF8g%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Place MyBatis Main Config file under src/main/resources

Jeff Butler
In Spring you can use the “classpath:” prefix before a resource to load it from the classpath (src/main/resources is typically on the classpath of an application). 

You can also use the MyBatis Spring boot starter and avoid the main configuration file altogether. 

Jeff Butler


From: [hidden email] <[hidden email]> on behalf of Vladimir Alarcon <[hidden email]>
Sent: Saturday, November 28, 2020 1:48:56 PM
To: [hidden email] <[hidden email]>
Subject: Place MyBatis Main Config file under src/main/resources
 
Hi,

Is it possible to place the MyBatis Main Config file
("mybatis-config.xml") file inside src/main/resources ?

I have a Spring Boot project. I'm using MyBatis XML mappers and they
are located under src/main/resources. Good.

However, the main MyBatis XML config file needs to be placed under
src/main/webapp; if I place it under src/main/resources MyBatis does
not find it. This has also the undesired side effect that it becomes
available as a web resource. For example, this shouldn't work but it
does:

  $ wget localhost:8080/mybatis-config.xml

This is how I configured it:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="configLocation" value="mybatis-config.xml" />
  <property name="objectFactory" ref="springBeanObjectFactory" />
</bean>

I'm using this configuration to set the "objectFactory" and read VOs
as Spring Beans.

Do you know any way to place it unser src/main/resources? A solution
using Java annotations is also welcome, but I haven't been able to
make it work.

Thank you,
Vlad

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CAP3Y0Vb3CwjxFcigbufw-4vzSG-DH_UeoF0NhuniQ2UPEgHF8g%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/SN7PR18MB4030B3D29355C35487871EFAF3F60%40SN7PR18MB4030.namprd18.prod.outlook.com.
Reply | Threaded
Open this post in threaded view
|

Re: Place MyBatis Main Config file under src/main/resources

Biao Huang
In the applicatioin.yml, you can specify the location of the mappers such as (placing the mapper files in the directory src/main/resources/mapper):

mybatis.mapper-locations: classpath:mapper/**/*.xml



Jeff Butler <[hidden email]> 于2020年11月29日周日 上午9:41写道:
In Spring you can use the “classpath:” prefix before a resource to load it from the classpath (src/main/resources is typically on the classpath of an application). 

You can also use the MyBatis Spring boot starter and avoid the main configuration file altogether. 

Jeff Butler


From: [hidden email] <[hidden email]> on behalf of Vladimir Alarcon <[hidden email]>
Sent: Saturday, November 28, 2020 1:48:56 PM
To: [hidden email] <[hidden email]>
Subject: Place MyBatis Main Config file under src/main/resources
 
Hi,

Is it possible to place the MyBatis Main Config file
("mybatis-config.xml") file inside src/main/resources ?

I have a Spring Boot project. I'm using MyBatis XML mappers and they
are located under src/main/resources. Good.

However, the main MyBatis XML config file needs to be placed under
src/main/webapp; if I place it under src/main/resources MyBatis does
not find it. This has also the undesired side effect that it becomes
available as a web resource. For example, this shouldn't work but it
does:

  $ wget localhost:8080/mybatis-config.xml

This is how I configured it:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="configLocation" value="mybatis-config.xml" />
  <property name="objectFactory" ref="springBeanObjectFactory" />
</bean>

I'm using this configuration to set the "objectFactory" and read VOs
as Spring Beans.

Do you know any way to place it unser src/main/resources? A solution
using Java annotations is also welcome, but I haven't been able to
make it work.

Thank you,
Vlad

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CAP3Y0Vb3CwjxFcigbufw-4vzSG-DH_UeoF0NhuniQ2UPEgHF8g%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/SN7PR18MB4030B3D29355C35487871EFAF3F60%40SN7PR18MB4030.namprd18.prod.outlook.com.


--
=====================================
QQ:     26664141
Skype: biao.mac
EMail:  [hidden email]

Tel: Home:  495312217000
Tel: Mobile: 4917620793369

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CAAPc23NvyfO_u86VfY%3DtKm2tO2b6qPWNJqi%2B39euHUhJYuQNMw%40mail.gmail.com.