spring-projects / spring-net

Spring Framework for .NET
http://www.springframework.net
Apache License 2.0
849 stars 376 forks source link

Spring is not injecting adoTemplate into AbstractTransactionalDbProviderSpringContextTests #71

Closed akhilkakar closed 10 years ago

akhilkakar commented 10 years ago

For the RC1, AdoTemplate is not getting injected automatically. I get the following exception when executing the test: "Unsatisfied dependency expressed through object property 'AdoTemplate'"

I have resolved this by explicitly defining the AdoTemplate spring object in my context file.

But when I was using an earlier version of Spring(version 2.0.0.35000), I was not setting the AdoTemplate.

Are there any changes done in the new Spring version, which requires the AdoTemplate to be set explicitly? Thanks.

lahma commented 10 years ago

Could you elaborate a bit more? What is the more specific dependency in the stack trace that is not injected? I don't see how AdoTemplate would ever be auto-injected if it is not defined in application context.

akhilkakar commented 10 years ago

Stacktrace:

SetUp : Spring.Objects.Factory.UnsatisfiedDependencyException : Error creating object with name 'DealingHibernateDaoTest' : Unsatisfied dependency expressed through object property 'AdoTemplate': Set this property value or disable dependency checking for this object. at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.PopulateObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\devenv\spring-net-spring-net-2.0.0-RC1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs: line 541 at Spring.Testing.NUnit.AbstractDependencyInjectionSpringContextTests.SetUp() in c:\devenv\spring-net-spring-net-2.0.0-RC1\src\Spring\Spring.Testing.NUnit\Testing\NUnit\AbstractDependencyInjectionSpringContextTests.cs: line 169

I am using AutoWiringMode.ByType

thomast74 commented 10 years ago

The ADO template is now in upper case writing.

To make it working I had to add the following line into your constructor.

DependencyCheck = false;

Worked for me.

akhilkakar commented 10 years ago

Thanks for your help Thomas. By setting DependencyCheck = false; worked for me as well.

sbohlen commented 10 years ago

I'm a bit confused (net necessarily a inique state for me ). Isn't that only going to succeed in the initial error simply being ignored (vs. having the AdoTemplate injected properly)?

-Steve B.

-----Original Message----- From: "akhilkakar" notifications@github.com Sent: ‎4/‎3/‎2014 2:53 PM To: "spring-projects/spring-net" spring-net@noreply.github.com Subject: Re: [spring-net] Spring is not injecting adoTemplate intoAbstractTransactionalDbProviderSpringContextTests (#71)

Thanks for your help Thomas. By setting DependencyCheck = false; worked for me as well. — Reply to this email directly or view it on GitHub.

thomast74 commented 10 years ago

Yes. It is only a work around. The issue was introduced with the latest version. It should be investigated what the real root cause is.

I will create a Jira ticket for it and try to figure it out.

akhilkakar commented 10 years ago

In the latest version, any class inheriting from AbstractTransactionalDbProviderSpringContextTests has to explicitly set the AdoTemplate property:

private AdoTemplate adoTemplate;
public IDbProvider DbProvider
        {
            set { adoTemplate = new AdoTemplate(value); }
        }

        public AdoTemplate AdoTemplate
        {
            get { return adoTemplate; }
            protected set { adoTemplate = value; }
        }

In the earlier version of Spring, it wasn't required to set the AdoTemplate explicity. It was initialised when DbProvider value was injected.

protected AdoTemplate adoTemplate;
public IDbProvider DbProvider
        {
            set
            {
                this.adoTemplate = new AdoTemplate(value);
            }
        }

public AdoTemplate AdoTemplate
        {
            get
            {
                return this.adoTemplate;
            }
        }

Hope this helps.

thomast74 commented 10 years ago

Is there a reason why Jira does not allow to select Spring.Net project when I create a new issue?

sbohlen commented 10 years ago

Hmmm...I created an issue not long ago, though in the process I uncovered that there were some odd permissions that had been improperly set. I'd thought we'd properly reset them, but its possible that some oddities remain there.

I'm traveling this week but can take a look at this over the weekend once I get back on dry land to ...

• verify your current permissions • determine whether I've the proper permissions to change yours as needed (I should have this as project owner/admin)

Its possible /likely that this issue extends to the settings of others on jira as well (i.e., it may affect all "project contributors") so we'd clearly want to resolve this asap for everyone should it prove to be a broader issue.

Will advise soon as I have a chance to investigate this further...!

-Steve B.

-----Original Message----- From: "Thomas Trageser" notifications@github.com Sent: ‎4/‎4/‎2014 3:09 AM To: "spring-projects/spring-net" spring-net@noreply.github.com Cc: "Steve Bohlen" sbohlen@gmail.com Subject: Re: [spring-net] Spring is not injecting adoTemplate intoAbstractTransactionalDbProviderSpringContextTests (#71)

Is there a reason why Jira does not allow to select Spring.Net project when I create a new issue? — Reply to this email directly or view it on GitHub.

thomast74 commented 10 years ago

The protected setter from

    public AdoTemplate AdoTemplate
    {
        get { return adoTemplate; }
        protected set { adoTemplate = value; }
    }

is the root cause. The Autowrie.ByType routine checks all properties that CanWrite as required.

I added a Pull Request that removes the AdoTemplate from the dependency check after autowiring.