Comments (26)
Seems there is a NPE in your code, isn't it?
from spring.
What are you trying to say? Of course there is a NPE in my code as "this.databaseConfiguration" is not Injected/Autowired as it should be when @MapperScan Annotations are present. Maybe I was not clear about that in my initial posting ;)
It feels like the sqlSessionFectory Bean gets created needed for @MapperScan but the Autowiring of dataSourceConfiguration did not happen at this point in time.
Just remove @MapperScan and add the Mappers manually - the code is working fine. Remove the manual adding of the Mappers and use @MapperScan --> NPE
from spring.
Sorry I am a bit lost. Why IDatabaseConfiguration should be injected? How is that related to @MapperScan?
from spring.
I have two Classes providing a DataSource. Both implementing IDatabaseConfiguration. Only one of this Class is used (@Profile usage of Spring) depending of running on an Application Server (using JNDI-Datasource) or standalone (using manual configured datasource for JUnit Testing). So I need the injection of the Bean which provides the Datasource.
How it is related to @MapperScan? You have to tell me ;) Why does the injection does not take place when @MapperScan is in place. As I wrote - when I have the @MapperScan annotation in place, the injection does not take place and the variable is Null. The bean sqlSessionFactory() provides is probably used by the @MapperScan magic but it looks like at this point in time, when the Bean is created to be used by @MapperScan the Injections did not happend.
from spring.
Ok I see. Thanks for the explanation.
Looks like an Spring issue because we do not autowire anything. But it is definetely worth investigating to know what is going on. Can you fork the repo and add a test isolating this behaviour?
from spring.
ZIP file containing a test directly sent by mail as attaching here seems not to be supported
from spring.
Thank you! I hope I will have some time next days to have a look into it.
from spring.
Hi again. I wrote a test out of your classes so I can add it to the project and make sure we do not break it in the future. But...unfortunately, it does not fail!
Maybe this has something to do with the loading order of the @configuration classes or the Spring version.
The test is in a forked repo.
https://github.com/emacarron/spring
https://github.com/emacarron/spring/commit/9b81096511468b6ae97e0a3a6fe9a2acfcc72adc
I added you as a collaborator to the repo. Can you play with it to try to reproduce it there?
from spring.
I'm also not able to reproduce this problem with the JUnit test. I guess there are just to many differences between how JUnit loads the classes and an AS-deployment does. I also tried spring 3.2.3
Are you able t reproduce it with the Archive I've sent you?
from spring.
Hi Eduardo,
I will take look at the project and let you know if I find something.
Bets wishes,
Lukasz
On Sun, Jun 23, 2013 at 8:14 AM, Eduardo Macarron
[email protected]:
Hi again. I wrote a test out of your classes so I can add it to the
project and make sure we do not break it in the future.
But...unfortunately, it does not fail!Maybe this has something to do with the loading order of the
@configuration https://github.com/Configuration classes or the Spring
version.The test is in a forked repo.
https://github.com/emacarron/spring
emacarron@9b81096https://github.com/emacarron/spring/commit/9b81096511468b6ae97e0a3a6fe9a2acfcc72adcI added you as a collaborator to the repo. Can you play with it to try to
reproduce it there?Reply to this email directly or view it on GitHubhttps://github.com//issues/10#issuecomment-19869707
.
Pozdrawiam serdecznie,
£ukasz Miros³aw
from spring.
Sorry. No reply.
from spring.
Why Closed? What reply? I said I was not able to create a Unit Test for this to reproduce but the error exists.
from spring.
Hi OlliL, neither you nor me can reproduce it. There is no news from Lukasz. Nobody is working on this and there is no info to start with it. There is no point in leaving open issues forever.
No problem in reopening it if you or any other can add more info.
from spring.
It turned out that my configuration was wrong. So I am not able to
reproduce this as well.
Cheers,
Lukasz
On Wed, Oct 9, 2013 at 8:36 PM, Eduardo Macarron
[email protected]:
Hi OlliL, neither you nor me can reproduce it. There is no news from
Lukasz. Nobody is working on this and there is no info to start with it.
There is no point in leaving open issues forever.No problem in reopening it if you or any other can add more info.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/10#issuecomment-25996422
.
Łukasz Mirosław, Ph.D.
Senior Research Associate
Institute of Informatics
Wrocław University of Technology
Wyb. Wyspiańskiego 27
PL50370 Wrocław, Poland
Email: [email protected]
Tel.: +48713203969
Web: www.ii.pwr.wroc.pl/~miroslaw http://www.ii.pwr.wroc.pl/%7Emiroslaw
from spring.
Thanks for the feedback Lukasz. Good to know that at least you solved your issue.
from spring.
Can anybody comment exactly what was wrong here? Whether it be configuration or otherwise? I am having the exact same issue: the presence of @MapperScan is causing the @Autowired injection of my Spring Environment attribute to be null. If I comment out MapperScan then it loads fine, if it is uncommented then the Environment attribute is null which of course prevents me from properly instantiating my Datasource.
Any help would be greatly appreciated
from spring.
Hi Collin. I have not been able to reproduce it so far. Can you provide a test or try to make this one fail?
https://github.com/emacarron/spring
from spring.
What a wild day. I have been converting our app to JavaConfig and working through the errors. This cropped up and blocked me for a couple hours. I eventually moved on and got other parts working and when I came back it was working again.
from spring.
This is by far the most elusive bug ever! ;)
from spring.
it's a must be solved bug.
from spring.
@pubyun Feel free to provide some information, a failing test or directly a patch. I promise we will have a look at it and apply it soon.
from spring.
I have the same issue to this very day. Here is a subset of the code I have. I had to go back to using other methods of selecting profiles (maven profiles and property files etc). Using JDBC Template and JPA via Spring ORM work but adding Mybatis Spring MapperScanner into the mix throws NPE with the injected property.
I've tried Excluding packages etc on the @componentscan and still no resolution other than explained workaround above.
https://gist.github.com/hooflung64/752761587221a3c1dcf1
from spring.
I got the bug related to that Environment is being null. I ran spring with debug log level, it seems that when adding the MapperScan annoation the Autowiring of Environment bean fails
here is the code
https://gist.github.com/blabadi/240fbd72e1e9abc54600
and here is my project structure and libraries
Note : as a work around i had to use PropertyPlaceholderConfig instead of Environment, it worked, but just letting you know about this behavior.
from spring.
Does anybody have any updates on this issue? This has somehow hit me again and I just cannot figure it out. I have a completely different app this time around (from my previous comment 2 years ago) which is Java 8 and Spring Boot. Everything worked fine in Spring Boot 1.2.5, and now I am trying to upgrade to Spring Boot 1.3.0 and I am getting this same issue where the presence of @MapperScan is causing the SqlSessionFactory bean to get created before the DataSource can even be injected.
from spring.
Very strange. I have a simple project with a datasource and mybatis with Spring Boot 1.3 which works. However, as soon as I add the spring-boot-starter-security dependency then suddenly the SqlSessionFactory bean tries to instantiate before the datasource is ready. Any thoughts would be appreciated.
from spring.
Spring boot support for mybatis is available. I don't know if it is up here yet. I haven't had a look at it yet but it's quite possible it might fix your issue. @emacarron knows a bit more about that project status.
from spring.
Related Issues (20)
- The query cache is not cleared after transaction rolls back to a savepoint HOT 3
- mapperLocations is overwritten HOT 1
- SqlSessionFactoryBean single resource, using wildcard causes a IOException HOT 4
- When Spring has multiple ApplicationContexts, it may throw BeanCreationNotAllowedException HOT 1
- Update dependency org.mybatis:mybatis to v3.5.13 on 2.1.x
- fix: change the event type that SqlSessionFactory is listening to on 2.1.x
- Drop support 1.3.x and 2.0.x
- Support processPropertyPlaceHolders option in mapper:scan and @MapperScan
- does mybatis-spring support to use customized mapper excludeFilters? HOT 1
- The logic regarding transaction rollback seems incorrect HOT 3
- The latest springboot using mybatis-spring-stater 3.0.2 throw exception "Invalid value type for attribute 'factoryBeanObjectType': java.lang.String" HOT 6
- The first query of maybatis takes longer than the second query. How to warm up in advance? HOT 1
- Switch baseline to Spring 6.1 and Spring Batch 5.1
- Support JDK 22 on CI
- why not override postProcessBeanDefinition method in ClassPathMapperScanner
- The latest springboot using mybatis-spring-stater 3.0.3-SNAPSHOT throw exception "Invalid value type for attribute 'factoryBeanObjectType': java.lang.String" HOT 5
- An idea to adapt to Spring 6.1 HOT 3
- MyBatisSystemException message is null
- Why @MapperScan scan all interface? Maybe only scan annotated with @Mapper is better? HOT 2
- mybatis-spring official docs for english responds 404 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring.