shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Project startup error Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

Open Mrljt497 opened this issue 2 years ago • 2 comments

For English only, other languages will not accept.

Before report a bug, make sure you have:

Searched open and closed GitHub issues. Read documentation: ShardingSphere Doc. Please pay attention on issues you submitted, because we maybe need more details. If no response anymore and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use? 5.1.1

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy? ShardingSphere-JDBC

Expected behavior Normal startup of the project

Actual behavior Project startup error

Reason analyze (If you can) Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

Mrljt497 avatar Sep 15 '22 09:09 Mrljt497

  • You didn't give a minimal reproducible example. ShardingSphere configuration doesn't use anything like sqlSessionFactory.

linghengqian avatar Sep 15 '22 14:09 linghengqian

可能是 你配置了多个datasource,但是没指定shardinsphere创建的datasource为Primary

linruzhou avatar Sep 17 '22 06:09 linruzhou

Hello , this issue has not received a reply for several days. This issue is supposed to be closed.

github-actions[bot] avatar Oct 08 '22 16:10 github-actions[bot]

I had the same problem. Several of the same issues were found in Issues, but none of them were actually solved, even the ones that were closed. Why mybatis can be assembled successfully if you comment out the configuration of rules? This should not be due to the sequence of automatic assembly.

我有同样的问题。在issue里类似的问题好几个,但是没有一个是真正解决了的,即使是那些关闭了的。为什么注释掉rules的配置,mybatis就能装配成功。这不该是自动装配的先后顺序导致的.

pengxianggui avatar Dec 25 '22 05:12 pengxianggui

Hi @pengxianggui, can you provide a demo to help reproduce this problem?

strongduanmu avatar Dec 25 '22 07:12 strongduanmu

Hi @pengxianggui, can you provide a demo to help reproduce this problem?

Thank you for your attention! Giving a full demo is a bit of a hassle, and I believe it will be easier to reproduce this problem if you rely on this package:

<dependency>
	<groupId>tk.mybatis</groupId>
	<artifactId>mapper-spring-boot-starter</artifactId>
</dependency>

This is my dependency analysis, for mybatis: image

My project is built on springboot 2.2.9

pengxianggui avatar Dec 26 '22 01:12 pengxianggui

@pengxianggui

  • I cannot reproduce your problem using ShardingSphere JDBC under pure JDBC 4.1 API. Without any context, I'm inclined to think that this is a compatibility issue of tk.mybatis:mapper-spring-boot-starter with your particular Mybatis version.

linghengqian avatar Dec 26 '22 02:12 linghengqian

  • I cannot reproduce your problem using ShardingSphere JDBC under pure JDBC 4.1 API. Without any context, I'm inclined to think that this is a compatibility issue of tk.mybatis:mapper-spring-boot-starter with your particular Mybatis version.

@linghengqian Thank you for your attention! Unfortunately, I changed tkmapper to mybatisplus, but I got the same result. If I comment out the rules configuration, through breakpoint debugging, it will execute Mybatis related AutoConfiguration, but if I set rules, these AutoConfiguration, Even the DataSourceAutoConfiguration won't assembly. This is my dependency analysis, for mybatisplus, It couldn't be simpler: image

很遗憾,我把tkmapper换成mybatisplus, 但得到的结果是样的。如果我注释掉rules配置,通过断点调试, 程序能顺利执行Mybatis的相关AutoConfiguration, 但如果我设置rules,这些AutoConfiguration,甚至连DataSourceAutoConfiguration都不会装配。 这是我关于mybatisplus的依赖分析,不能更简单了。

pengxianggui avatar Dec 26 '22 04:12 pengxianggui

@pengxianggui If you don't provide the full stack and unittests, it's a black box. I tested Mybatis Plus earlier and everything works fine.

linghengqian avatar Dec 26 '22 05:12 linghengqian

@pengxianggui If you don't provide the full stack and unittests, it's a black box. I tested Mybatis Plus earlier and everything works fine.

@linghengqian Thanks for you attention! I fixed the problem, which was caused by another package I relied on.

By the way, If there are any usage problems, where can we communicate?

pengxianggui avatar Dec 27 '22 06:12 pengxianggui

@pengxianggui If you don't provide the full stack and unittests, it's a black box. I tested Mybatis Plus earlier and everything works fine.

@linghengqian Thanks for you attention! I fixed the problem, which was caused by another package I relied on.

By the way, If there are any usage problems, where can we communicate?

  • For the most part, all communication happens on Github Issues.

linghengqian avatar Dec 27 '22 06:12 linghengqian

@pengxianggui If you don't provide the full stack and unittests, it's a black box. I tested Mybatis Plus earlier and everything works fine.

@linghengqian Thanks for you attention! I fixed the problem, which was caused by another package I relied on. By the way, If there are any usage problems, where can we communicate?

  • For the most part, all communication happens on Github Issues.

All right. I have a question, take the official demo for example.

I used the binding table to avoid the Cartesian product, so I have to use orderId as the sharding field, but in reality, I need to sharding by year, so I should take order_time as the sharding field. Because there are only interval conditions for orderTime in the paging query condition.

How can I avoid Cartesian products in associative table queries while using orderTime sharding? Thanks for your answer!

好吧。我有一个问题,以官方的demo为例。 我使用了绑定表避免笛卡尔积,因此我必须使用orderId作为分片字段,但是实际情况,我需要按年份分片,我应该取order_time作为分片字段。因为分页查询条件里只有针对orderTime的区间条件。 我如何在使用orderTime分片的同时,又能在关联表查询中避免笛卡尔积呢? 感谢您的解答!

pengxianggui avatar Dec 27 '22 07:12 pengxianggui

@pengxianggui

  • I don't seem quite sure what the table structure looks like for the example you're talking about. I'm on my Christmas break, you can open a new question issue.

linghengqian avatar Dec 27 '22 08:12 linghengqian

  • Christmas

well, happy christmas!

pengxianggui avatar Dec 27 '22 09:12 pengxianggui

Resolved.

RaigorJiang avatar Jan 29 '23 03:01 RaigorJiang