托管属性(服务)上的NullPointer异常



我在我的应用程序上面临空指针异常,我用@Repository注释Dao, @Service的服务,@Controller的控制器和@ManagedProperty的服务,我怀疑我的应用程序上下文配置得不好,所以这里有:

 <?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:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xml:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
                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
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
    <!-- Enable Spring Annotation Configuration -->
    <context:annotation-config/> 
    <!-- Scan for all of Spring components such as Spring Service -->
    <context:component-scan base-package="com.domain.nameOfapp.*" />
    <!-- Necessary to get the entity manager injected into the factory bean -->
    <bean
        class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <!-- Define Hibernate JPA Vendor Adapter -->
    <bean id="jpaVendorAdapter"
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
    </bean>
    <!-- Entity Manager Factory -->
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="jpa-persistence" />
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
        <property name="packagesToScan">
            <list>
                <value>com.domain.nameOfapp.*</value>
            </list>
        </property>
    </bean>
    <!-- Transaction Manager -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <!-- Detect @Transactional -->
    <tx:annotation-driven transaction-manager="transactionManager"  />
</beans>

任何帮助将是伟大的!由于

您的组件扫描需要如下所示,

<context:component-scan base-package="com.domain.nameOfapp" />

这将扫描这个包下的所有类,包括所有子包。

同样使用@ManagedProperty,您正在尝试自动连接spring服务bean吗?我认为你应该使用@Autowired

最新更新