我能';t使用spring实例化没有参数的类
我有一个没有参数的构造函数的类,我想使用spring进行实例化,但出现以下错误: 创建上下文“spring.root”时出错:无法实例化没有无参数构造函数的类 下面是配置文件:我能';t使用spring实例化没有参数的类,spring,spring.net,Spring,Spring.net,我有一个没有参数的构造函数的类,我想使用spring进行实例化,但出现以下错误: 创建上下文“spring.root”时出错:无法实例化没有无参数构造函数的类 下面是配置文件: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <sectionGroup name="spring"> <section name="conte
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects" />
</context>
<objects xmlns="http://www.springframework.net">
<object name="metier" type="Metier.ImpotMetier, Metier">
</object>
</objects>
</spring>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
问题:我如何实例化这个类并在另一个项目中使用它的方法?创建一个无参数构造函数?我认为spring不同意你的观点-这个类没有一个可见的无参数构造函数,或者你创建了
importMetier
类,或者它在你引用的库中?如果课程是你的,请将其添加到问题中。如果不是,那么库创建者可能有很好的理由不使用无参数构造函数,您应该使用其他构造函数之一。是的,在我创建的Metier库中定义了“ImportMetier”类,我想使用spring实例化这个类。我的问题是,当我在ImportMetier类中添加一个没有参数的构造函数时,我忘记了构建它,这就是为什么spring抛出错误啊,很高兴你解决了这个问题。考虑回答你自己的问题,这样每个人都知道你的问题已经解决了。