无法自动装配字段(Could not autowire field)
我正在使用
Hibernate 4
+Spring MVC 4
,当我启动Apache Tomcat Server 8
出现此错误:Error creating bean with name 'welcome': Injection of autowired dependencies failed; Could not autowire field: private dao.IRegion controller.welcome.regionI; No qualifying bean of type [dao.IRegion] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
这是我的Hibernate配置,其中包含
<property name="packagesToScan" value="dao" />
:<?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-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <context:property-placeholder location="persistence-mysql.properties" /> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan" value="dao" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> </props> </property> </bean> <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> --> <bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp2.BasicDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.user}" /> <property name="password" value="${jdbc.pass}" /> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="persistenceExceptionTranslationPostProcessor" class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> </beans>
dao是我放置我的dao和接口的包。
我的区域界面
dao.IRegion
:public interface IRegion<T extends Serializable> { List<T> findAll(); }
我的地区DAO
dao.RegionDAO
@Repository public class RegionDAO implements IRegion < Region > { @Autowired private SessionFactory sessionFactory; @Override public List<Region> findAll() { return sessionFactory.getCurrentSession().createQuery("from Region").list(); } }
我的控制器
@Controller public class welcome { @Autowired private IRegion<Region> regionI; .... }
我的servlet调度员
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:default-servlet-handler /> <context:component-scan base-package="controller"/> <mvc:annotation-driven /> <mvc:resources mapping="/resources/**" location="/resources/" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
I'm using
Hibernate 4
+Spring MVC 4
and when i startApache Tomcat Server 8
I got this error :Error creating bean with name 'welcome': Injection of autowired dependencies failed; Could not autowire field: private dao.IRegion controller.welcome.regionI; No qualifying bean of type [dao.IRegion] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
here's my Hibernate Configuration which contain
<property name="packagesToScan" value="dao" />
:<?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-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <context:property-placeholder location="persistence-mysql.properties" /> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan" value="dao" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> </props> </property> </bean> <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> --> <bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp2.BasicDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.user}" /> <property name="password" value="${jdbc.pass}" /> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="persistenceExceptionTranslationPostProcessor" class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> </beans>
dao is the package where i put my dao and interfaces.
My region Interface
dao.IRegion
:public interface IRegion<T extends Serializable> { List<T> findAll(); }
my Region DAO
dao.RegionDAO
@Repository public class RegionDAO implements IRegion < Region > { @Autowired private SessionFactory sessionFactory; @Override public List<Region> findAll() { return sessionFactory.getCurrentSession().createQuery("from Region").list(); } }
My Controller
@Controller public class welcome { @Autowired private IRegion<Region> regionI; .... }
My servlet dispatcher
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:default-servlet-handler /> <context:component-scan base-package="controller"/> <mvc:annotation-driven /> <mvc:resources mapping="/resources/**" location="/resources/" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
原文:https://stackoverflow.com/questions/24469109
最满意答案
您的
paint
方法不会覆盖超类方法,因此不会调用它。 将签名更改为:public void paint(Graphics g, JComponent c)
...并添加
@Override
注释,以便将来编译器可以为您找到问题...Your
paint
method doesn't override a superclass method, so it's not being called. Change the signature to:public void paint(Graphics g, JComponent c)
... and add the
@Override
annotation so that in future, the compiler can find the problem for you...
相关问答
更多-
把它当作: Thread audioplay=null; 正常启动线程! 然后! if (audioplay != null) { bg.Terminate(); playplayer.close(); try { audioplay.join(); } catch (InterruptedException ex) { //catch the exception } System.out.p ...
-
你不需要这里的下划线。 只有在想通过eta-expansion将方法转换为函数时才需要下划线。 这不是必需的,因为formula已经是type () => Boolean的函数,这是Property类正在寻找的。 def property(propName: String)(formula: () => Boolean) { properties += new Property(propName, formula) } You don't need the underscore here. T ...
-
如何使用JLayer停止声音(How to stop a sound using JLayer)[2022-09-02]
我不知道你正在使用什么库,但也许你可以在你的播放器类中找到一个“停止”方法。 I don't know what library you are using, but maybe you could find a "stop" method in your player class. -
唯一的区别是在一种情况下,面板用JLayer装饰。 JPanel和JLayer不同之处在于JLayer实现了Scrollable接口,但JPanel不支持。 getScrollableTracksViewportWidth()方法控制添加到视口的组件是否应以其首选大小或视口宽度显示。 JLayer委派给JPanel,但由于JPanel没有实现Scrollable接口,JLayer实现将返回“false”,这意味着组件应该以其首选的宽度显示。 所以解决这个问题的方法是为JLayer使用包装器面板: //scr ...
-
在JRE6中替代JLayer?(Alternate for JLayer in JRE6?)[2023-11-25]
JXLayer 3.0是JLayer所基于的,我在基于Java 6的项目中广泛使用(它正在转向Java 8,但我们仍然会使用它,因为它不值得我们努力替换它,因为它是我们需要的jlob) JXLayer 3.0 is what JLayer is based on and I use extensively in our Java 6 based project (which is moving to Java 8, but we'll still use it as its not worth our ef ... -
更改consiguePath以从getResource返回结果URL public static URL consiguePath(int i) { return AppUtils.class.getClass().getResource("/Movimiento/" + mapa.get(i)); } 然后使用它的InputStream传递给Player try { URL url = AppUtils.consiguePath(12); Player player = ne ...
-
您应该在另一个Thread而不是Event Dispatch Thread上加载该文件。 假设你的loadFromFile方法阻塞直到它加载文件,你就可以隐藏该层,但你必须隐藏在Event Dispatch Thread而不是你为加载文件而启动的新Thread 。 删除你的计时器并用这个替换你的try块: try { new Thread(new Runnable(){ public void run() { dataManag ...
-
没有看到你的日志,这是一场猜测游戏 - 但是,有许多事情需要研究。 创建 首先,您需要确保您的create操作可以实际执行您想要的操作。 我注意到有一种方法。 .follow! 包括: def create @user = User.find(params[:relationship][:followed_id]) current_user.follow!(@user) respond_to do |format| format.html { redirect_to @u ...
-
使用JLayer解码MP3文件(Decoding MP3 files with JLayer)[2023-07-05]
自己搞清楚了。 Bitstream bitStream = new Bitstream(new FileInputStream("path/to/audio.mp3")); while(condition){ Decoder decoder = new Decoder(); int[] samples = decoder.decodeFrame(bitStream.readFrame(), bitStream); //returns the next 2304 samples bi ... -
您的paint方法不会覆盖超类方法,因此不会调用它。 将签名更改为: public void paint(Graphics g, JComponent c) ...并添加@Override注释,以便将来编译器可以为您找到问题... Your paint method doesn't override a superclass method, so it's not being called. Change the signature to: public void paint(Graphics g, JC ...