简体   繁体   English

Bean必须为'org.hibernate.SessionFactory'类型

[英]Bean must be of 'org.hibernate.SessionFactory' type

I have been following an online training ( https://www.udemy.com/building-an-e-commerce-store-using-java-spring-framework ) and when i finish the applicationContext.xml i get the following errors. 我一直在接受在线培训( https://www.udemy.com/building-an-e-commerce-store-using-java-spring-framework ),当我完成applicationContext.xml ,出现以下错误。

ref="sessionFactory" indicates the following: ref="sessionFactory"表示以下内容:

Bean must be of org.hibernate.SessionFactory type less... (Ctrl+F1) Checks value types for Spring injections (properties & constructor arguments) Bean必须为org.hibernate.SessionFactory类型,类型小于...(Ctrl + F1)检查Spring注入的值类型(属性和构造函数参数)

And ref="dataSource" indicates datasource unexpected . ref="dataSource"表示datasource unexpected

I do not understand what i am missing. 我不明白我在想什么。 How should i correct this? 我应该如何纠正呢?

I have uploaded my project to github: https://github.com/arendkolk/Wholesaleproducts 我已将项目上传到github: https : //github.com/arendkolk/Wholesaleproducts

applicationContext.xml : applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.h2.Driver" />
        <property name="url" value="jdbc:h2:tcp://localhost/~/test" />
        <property name="username" value="sa" />
        <property name="password" value="" />
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
        <property name="dataSource" ref="dataSource"></property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
            </props>
        </property>
        <property name="packagesToScan">
            <list>
                <value>com.wholesaleproducts</value>
            </list>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

</beans>

This is my pom.xml : 这是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>club.wholesaleproducts</groupId>
    <artifactId>wholesaleproducts</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.1.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.1.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.190</version>
    </dependency>

    <dependencies>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
    </dependencies>

</project>

In the pom.xml file put all your dependency inside the dependencies tag.Then it will build perfectly. 在pom.xml文件中,将您所有的依赖项放入依赖项标签中,然后它将完美构建。

<dependencies>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.1.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.1.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.190</version>
    </dependency>
</dependencies>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有类型[org.hibernate.SessionFactory]的限定bean - No qualifying bean of type [org.hibernate.SessionFactory] Spring Hibernate:没有匹配的org.hibernate.SessionFactory类型的bean - Spring Hibernate : No matching bean of type org.hibernate.SessionFactory 需要一个无法找到的&#39;org.hibernate.SessionFactory&#39;类型的bean - required a bean of type 'org.hibernate.SessionFactory' that could not be found 考虑在您的配置中定义类型为“org.hibernate.SessionFactory”的 bean - Consider defining a bean of type 'org.hibernate.SessionFactory' in your configuration 找不到类型为“ org.hibernate.SessionFactory”的bean - A bean of type 'org.hibernate.SessionFactory' that could not be found AppFuse + wicket:没有类型[org.hibernate.SessionFactory]的限定bean - AppFuse + wicket: No qualifying bean of type [org.hibernate.SessionFactory] NoSuchBeanDefinitionException:找不到依赖项类型为[org.hibernate.SessionFactory]的合格bean - NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency 找不到依赖项类型为[org.hibernate.SessionFactory]的合格Bean - No qualifying bean of type [org.hibernate.SessionFactory] found for dependency 通过“sessionFactory”未满足的依赖性; 没有可用的“org.hibernate.SessionFactory”类型的合格 bean - Unsatisfied dependency through 'sessionFactory'; No qualifying bean of type 'org.hibernate.SessionFactory' available 类型构造函数的参数 0 需要一个无法找到的类型为“org.hibernate.SessionFactory”的 bean - Parameter 0 of constructor in type required a bean of type 'org.hibernate.SessionFactory' that could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM