Spring @Autowired not working

后端 未结 7 1955
再見小時候
再見小時候 2021-02-08 12:35

I have some problems wth autowire annotation. My app looks like this:

Here is controller:

@Controller
public class MyController {
    @Autowired
    @Qua         


        
相关标签:
7条回答
  • 2021-02-08 13:02
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:mvc="http://www.springframework.org/schema/mvc" 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/tx http://www.springframework.org/schema/tx/spring-tx.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">
    
        <!-- Specifying base package of the Components like Controller, Service, 
            DAO -->
        <context:component-scan base-package="com.jwt" />
    
        <!-- Getting Database properties -->
        <context:property-placeholder location="classpath:application.properties" />
    
        <!-- DataSource -->
        <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
            id="dataSource">
            <property name="driverClassName" value="${database.driver}"></property>
            <property name="url" value="${database.url}"></property>
            <property name="username" value="${database.user}"></property>
            <property name="password" value="${database.password}"></property>
        </bean>
    
        <!-- Hibernate SessionFactory -->
        <bean id="sessionFactory"
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"></property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                    <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                    <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                </props>
            </property>
        </bean>
    
    </beans>
    
    0 讨论(0)
提交回复
热议问题