Note that there are some explanatory texts on larger screens.

plurals
  1. POAutowire doesn't work on servlets
    text
    copied!<p>I can't figure out why Autowired of DAOs classes works fine in Test classes but not in servlets. web.xml file load correctly context configuration as i can see by the log, so the problem must be in my applicationContext file.</p> <p>This is my servlet:</p> <pre><code>@Controller public class TestAutowired extends HttpServlet { private static final long serialVersionUID = 1L; @Autowired private IUserDao uDao; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { uDao.getUserById(1); } } </code></pre> <p>And this is my ApplicationContext (configuration.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!-- Spring configuration --&gt; &lt;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" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=...&gt; &lt;context:component-scan base-package="com.firststepteam.dao"&gt; &lt;context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/&gt; &lt;/context:component-scan&gt; &lt;context:component-scan base-package="com.firststepteam.services"&gt; &lt;context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/&gt; &lt;/context:component-scan&gt; &lt;context:component-scan base-package="com.firststepteam.servlet"&gt; &lt;context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/&gt; &lt;/context:component-scan&gt; &lt;!-- View resolver -&gt; JSP --&gt; &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/&gt; &lt;property name="prefix" value="/WEB-INF/jsp/"/&gt; &lt;property name="suffix" value=".jsp"/&gt; &lt;/bean&gt; &lt;!-- PropertyPlaceholderConfigurer --&gt; &lt;bean id="placeHolder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="locations" value="classpath:hostingData.conf" /&gt; &lt;/bean&gt; &lt;!-- DataSource --&gt; &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${jdbc.db.driverClassName}" /&gt; &lt;property name="url" value="${jdbc.db.url}" /&gt; &lt;property name="username" value="${jdbc.db.username}" /&gt; &lt;property name="password" value="${jdbc.db.password}" /&gt; &lt;/bean&gt; &lt;!-- JPA E HIBERNATE --&gt; &lt;bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="database" value="MYSQL" /&gt; &lt;property name="generateDdl" value="true" /&gt; &lt;/bean&gt; &lt;!-- ENTITY MANAGER FACTORY --&gt; &lt;bean id="dbEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="persistenceUnitName" value="fs_db" /&gt; &lt;property name="jpaVendorAdapter" ref="jpaVendorAdapter" /&gt; &lt;/bean&gt; &lt;tx:annotation-driven /&gt; &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="entityManagerFactory" ref="dbEntityManagerFactory" /&gt; &lt;/bean&gt; &lt;bean class = "org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /&gt; &lt;/beans&gt; </code></pre> <p>any hint?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload