2012-03-20 4 views
3

Je suis nouveau dans .NET. J'ai utilisé Spring Framework et Hibernate auparavant en Java, mais c'est ma première en .NET. Pour développer mon application, j'utilise la solution Spring.Northwind comme exemple.Spring.NET - Référence d'objet non définie sur une instance d'un objet

La cartographie est mise en veille prolongée:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> 
    <class name="EMSApplication.Domain.Employee, EMSApplication.Domain" table="ems_Employees" proxy="EMSApplication.Domain.IEmployee, EMSApplication.Domain" lazy="true"> 
     <id name="Id" type="System.Int32"> 
     <column name="Id" not-null="true"/> 
     <generator class="native"/> 
     </id> 
     <property name="Username" type="System.String"> 
     <column name="Username" not-null="true"/> 
     </property> 
     <property name="Firstname" type="System.String"> 
     <column name="Firstname" not-null="true"/> 
     </property>  
    </class>  
</hibernate-mapping> 

Comme vous pouvez le voir le champ des employés de classe ne comporte que trois. Il implémente IEmployee qui consiste en la définition des méthodes get et set de ces champs (si vous voulez voir ces classes je peux fournir).

Maintenant, le web.config j'ai, je l'ai mis au printemps comme sectionGroup et défini comme:

<configSections> 
    <sectionGroup name="spring"> 
    <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/> 
    <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core"/> 
    </sectionGroup> 
    <section name="databaseSettings" type="System.Configuration.NameValueSectionHandler"/> 
</configSections> 
<spring> 
    <parsers/> 
    <context> 
    <resource uri="~/Web.xml"/> 
    </context> 
</spring> 
<databaseSettings> 
    <add key="db.datasource" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\JYM.mdf;Integrated Security=True;User Instance=True"/> 
</databaseSettings> 

Aussi j'ai ajouté Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName clé dans appsettings:

<appSettings> 
    <add key="Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName" value="NHibernateSessionFactory"/> 
</appSettings> 

Les httpModules du système .web a les entrées suivantes:

Et enfin le printemps ressources Web.xml a les objets suivants:

<object type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core"> 
    <property name="ConfigSections" value="databaseSettings"/> 
</object> 

<db:provider id="DbProvider" provider="System.Data.SqlClient" connectionString="Data Source=|DataDirectory|\JYM.mdf"/> 

<object id="NHibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate32"> 
    <property name="DbProvider" ref="DbProvider"/> 
    <property name="MappingResources"> 
    <list> 
     <value>assembly://EMSApplication/Domain/EMSApplication.hbm.xml</value> 
    </list> 
    </property> 
    <property name="HibernateProperties"> 
    <dictionary> 
     <entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/> 
     <entry key="dialect" value="NHibernate.Dialect.MsSql2008Dialect"/> 
     <entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/> 
     <entry key="proxyfactory.factory_class" value="NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernate"/> 
     <entry key="show_sql" value="true"/> 
     <entry key="hbm2ddl.auto" value="update"/> 
     <entry key="cache.use_query_cache" value="true"/> 
    </dictionary> 
    </property> 

    <property name="ExposeTransactionAwareSessionFactory" value="true" /> 
</object> 

<object id="transactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate32"> 
    <property name="DbProvider" ref="DbProvider"/> 
    <property name="SessionFactory" ref="NHibernateSessionFactory"/> 
</object> 

<object type="Spring.Dao.Attributes.PersistenceExceptionTranslationPostProcessor, Spring.Data"/> 

<object id="EmployeeDao" type="EMSApplication.NHibernate.HibernateEmployeeDao"> 
    <property name="SessionFactory" ref="NHibernateSessionFactory"/> 
</object> 

<tx:attribute-driven transaction-manager="transactionManager"/> 

Maintenant, quand je commence debug à partir de Visual Studio 2010 Je reçois

System.NullReferenceException: référence d'objet non définie à une instance d'un objet .

La trace complète de la pile est:

[NullReferenceException: Object reference not set to an instance of an object.] 
    System.Xml.XmlReader.CalcBufferSize(Stream input) +14 
    System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, String baseUriStr, Stream stream, Byte[] bytes, Int32 byteCount, Encoding encoding) +66 
    System.Xml.XmlTextReaderImpl..ctor(String url, Stream input, XmlNameTable nt) +93 
    System.Xml.XmlTextReader..ctor(Stream input) +74 
    NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:631 

[MappingException: Could not configure datastore from input stream ] 
    NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:342 
    NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:641 
    NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:611 
    Spring.Data.NHibernate.LocalSessionFactoryObject.AfterPropertiesSet() in c:\_prj\spring-net\trunk\src\Spring\Spring.Data.NHibernate20\Data\NHibernate\LocalSessionFactoryObject.cs:599 
    Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InvokeInitMethods(Object target, String name, IConfigurableObjectDefinition definition) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:1294 
    Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:1890 
    Spring.Objects.Factory.Support.WebObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Objects\Factory\Support\WebObjectFactory.cs:450 
    Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:921 

[ObjectCreationException: Error creating object with name 'NHibernateSessionFactory' defined in 'file [D:\Code\EMSApplication\EMSApplication\Web.xml] line 14' : Initialization of object failed : Could not configure datastore from input stream ] 
    Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:938 
    Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:2144 
    Spring.Objects.Factory.Support.WebObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Objects\Factory\Support\WebObjectFactory.cs:299 
    Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:2065 
    Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:1826 
    Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\DefaultListableObjectFactory.cs:770 
    Spring.Objects.Factory.ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(IListableObjectFactory factory, Type type, Boolean includePrototypes, Boolean includeFactoryObjects) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\ObjectFactoryUtils.cs:268 
    Spring.Dao.Support.PersistenceExceptionTranslationInterceptor.DetectPersistenceExceptionTranslators(IListableObjectFactory objectFactory) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Dao\Support\PersistenceExceptionTranslationInterceptor.cs:155 
    Spring.Dao.Support.PersistenceExceptionTranslationInterceptor..ctor(IListableObjectFactory objectFactory) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Dao\Support\PersistenceExceptionTranslationInterceptor.cs:73 
    Spring.Dao.Attributes.PersistenceExceptionTranslationAdvisor..ctor(IListableObjectFactory objectFactory, Type repositoryAttributeType) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Dao\Attributes\PersistenceExceptionTranslationAdvisor.cs:63 
    Spring.Dao.Attributes.PersistenceExceptionTranslationPostProcessor.set_ObjectFactory(IObjectFactory value) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Dao\Attributes\PersistenceExceptionTranslationPostProcessor.cs:95 
    Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:1886 
    Spring.Objects.Factory.Support.WebObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Objects\Factory\Support\WebObjectFactory.cs:450 
    Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:930 
    Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:2144 
    Spring.Objects.Factory.Support.WebObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Objects\Factory\Support\WebObjectFactory.cs:299 
    Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:2065 
    Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:1826 
    Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\DefaultListableObjectFactory.cs:770 
    Spring.Context.Support.AbstractApplicationContext.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs:1383 
    Spring.Context.Support.AbstractApplicationContext.RegisterObjectPostProcessors(IConfigurableListableObjectFactory objectFactory) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs:652 
    Spring.Context.Support.AbstractApplicationContext.Refresh() in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs:1000 
    Spring.Context.Support.WebApplicationContext..ctor(WebApplicationContextArgs args) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:125 
    Spring.Context.Support.WebApplicationContext..ctor(String name, Boolean caseSensitive, String[] configurationLocations) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:82 
    _dynamic_Spring.Context.Support.WebApplicationContext..ctor(Object[]) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Caching\AspNetCache.cs:126 
    Spring.Reflection.Dynamic.SafeConstructor.Invoke(Object[] arguments) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Reflection\Dynamic\DynamicConstructor.cs:116 
    Spring.Context.Support.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:563 
    Spring.Context.Support.ContextInstantiator.InstantiateContext() in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:508 
    Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:351 
    Spring.Context.Support.WebContextHandler.InstantiateContext(IApplicationContext parent, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebContextHandler.cs:127 
    Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:289 

[ConfigurationErrorsException: Error creating context 'spring.root': Could not configure datastore from input stream ] 
    System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) +199 
    System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) +1153 
    System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) +1468 
    System.Configuration.BaseConfigurationRecord.GetSection(String configKey) +41 
    System.Web.HttpContext.GetSection(String sectionName) +52 
    System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName) +57 
    System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey) +6 
    System.Configuration.ConfigurationManager.GetSection(String sectionName) +78 
    Spring.Util.ConfigurationUtils.GetSection(String sectionName) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Util\ConfigurationUtils.cs:71 
    Spring.Context.Support.WebApplicationContext.GetContextInternal(String virtualPath) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:335 
    Spring.Context.Support.WebApplicationContext.GetRootContext() in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:223 
    Spring.Context.Support.WebSupportModule.Init(HttpApplication app) in c:\_prj\spring-net\trunk\src\Spring\Spring.Web\Context\Support\WebSupportModule.cs:175 
    System.Web.HttpApplication.InitModulesCommon() +172 
    System.Web.HttpApplication.InitModules() +43 
    System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +828 
    System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +304 
    System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +107 
    System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +327 

Ici comme vous pouvez le voir:

[ObjectCreationException: objet la création d'erreur avec le nom 'NHibernateSessionFactory' défini dans le « fichier [D : \ Code \ EMSApplication \ EMSApplication \ Web.xml] ligne 14 ': L'initialisation de l'objet a échoué: Impossible de configurer la banque de données à partir du flux d'entrée ]

Donc, je suis incapable de comprendre comment résoudre ce problème. Toute aide ou suggestion que j'apprécie vraiment.

Merci.

NB: Je ne change pas les paramètres dans IIS 7.


Edit:

Ce sont les références utilisées:

enter image description here

Répondre

4

Est-assembly://EMSApplication/Domain/EMSApplication.hbm.xml une ressource intégrée (VS -> Propriétés -> Actions de construction -> Ressource incorporée)?

Cependant, au lieu de pointer vers la ressource incorporée Je suggère de signaler à l'Assemblée comme @Marijn déjà souligné dans post précédent:

<propertyname="MappingAssemblies"> 
    <list> 
    <value>EMSApplication.Domain</value> <-- Assembly name 
    </list> 
</property 
Questions connexes