Code Monkey home page Code Monkey logo

Comments (26)

emacarron avatar emacarron commented on June 2, 2024

Seems there is a NPE in your code, isn't it?

from spring.

OlliL avatar OlliL commented on June 2, 2024

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.

emacarron avatar emacarron commented on June 2, 2024

Sorry I am a bit lost. Why IDatabaseConfiguration should be injected? How is that related to @MapperScan?

from spring.

OlliL avatar OlliL commented on June 2, 2024

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.

emacarron avatar emacarron commented on June 2, 2024

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.

OlliL avatar OlliL commented on June 2, 2024

ZIP file containing a test directly sent by mail as attaching here seems not to be supported

from spring.

emacarron avatar emacarron commented on June 2, 2024

Thank you! I hope I will have some time next days to have a look into it.

from spring.

emacarron avatar emacarron commented on June 2, 2024

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.

OlliL avatar OlliL commented on June 2, 2024

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.

lmiroslaw avatar lmiroslaw commented on June 2, 2024

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/9b81096511468b6ae97e0a3a6fe9a2acfcc72adc

I 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.

emacarron avatar emacarron commented on June 2, 2024

Sorry. No reply.

from spring.

OlliL avatar OlliL commented on June 2, 2024

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.

emacarron avatar emacarron commented on June 2, 2024

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.

lmiroslaw avatar lmiroslaw commented on June 2, 2024

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.

emacarron avatar emacarron commented on June 2, 2024

Thanks for the feedback Lukasz. Good to know that at least you solved your issue.

from spring.

collinpeters avatar collinpeters commented on June 2, 2024

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.

emacarron avatar emacarron commented on June 2, 2024

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.

collinpeters avatar collinpeters commented on June 2, 2024

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.

emacarron avatar emacarron commented on June 2, 2024

This is by far the most elusive bug ever! ;)

from spring.

pubyun avatar pubyun commented on June 2, 2024

it's a must be solved bug.

from spring.

emacarron avatar emacarron commented on June 2, 2024

@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.

hooflung64 avatar hooflung64 commented on June 2, 2024

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.

blabadi avatar blabadi commented on June 2, 2024

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
image

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.

collinpeters avatar collinpeters commented on June 2, 2024

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.

collinpeters avatar collinpeters commented on June 2, 2024

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.

hazendaz avatar hazendaz commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.