Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧自动线空值_Java_Spring_Spring Mvc - Fatal编程技术网

Java 弹簧自动线空值

Java 弹簧自动线空值,java,spring,spring-mvc,Java,Spring,Spring Mvc,我有一个与弹簧自动布线组件的问题。我正在尝试将bean用户存储库注入java类读取器。使用autowire注释时,对象始终为空。我尝试将属性“userRepository”添加到spring-config.xmlbean“reader”中,但这也不起作用。少了什么 spring-config.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schem

我有一个与弹簧自动布线组件的问题。我正在尝试将bean用户存储库注入java类读取器。使用autowire注释时,对象始终为空。我尝试将属性“userRepository”添加到spring-config.xmlbean“reader”中,但这也不起作用。少了什么

spring-config.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"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package="reader" />
<context:annotation-config/>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.sqlite.JDBC"/>
    <property name="url" value="jdbc:sqlite:C:/Users/Piotr/Downloads/projekt na projekt/IntelliDOM/IntelliDOM.sqlite"/>
    <property name="username" value=""/>
    <property name="password" value=""/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="userRepository" class="repository.UserRepositoryHibernate">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

</beans>
应用程序的上下文是否有问题?为什么这个豆子不能注射? Spring版本:2.5.6

编辑: hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
  <property name="show_sql">true</property>
  <property name="format_sql">true</property>
  <property name="dialect">org.hibernate.dialect.SQLiteDialect</property>
  <property name="connection.driver_class">org.sqlite.JDBC</property>
  <property name="connection.url">jdbc:sqlite:IntelliDOM.sqlite</property>
  <property name="connection.username"></property>
  <property name="connection.password"></property>
  <property name="hibernate.hbm2ddl.auto">update</property>

  <mapping class="entity.User"/>
  </session-factory>
</hibernate-configuration>

UserRepositoryHibernate是否实现UserRepository?Reader类在Reader包中,对吗?您如何初始化Reader类实例?您在sessionFactory的类中尝试过org.springframework.orm.hibernate3.annotation.AnnotationationationSessionFactoryBean吗?您在哪里定义了hibernate方言?@user3145373ツ 我打赌注入过程很好,OP正在手动初始化bean:新阅读器;或者类似的东西。
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
  <property name="show_sql">true</property>
  <property name="format_sql">true</property>
  <property name="dialect">org.hibernate.dialect.SQLiteDialect</property>
  <property name="connection.driver_class">org.sqlite.JDBC</property>
  <property name="connection.url">jdbc:sqlite:IntelliDOM.sqlite</property>
  <property name="connection.username"></property>
  <property name="connection.password"></property>
  <property name="hibernate.hbm2ddl.auto">update</property>

  <mapping class="entity.User"/>
  </session-factory>
</hibernate-configuration>