国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

Spring4.3.7注解 @Autowired java.lang.NullPointerException

瀏覽:98日期:2023-12-31 16:34:17

問題描述

UserAction中通過@Autowired注入UserServiceImpl無效,得到對象為空UserAction.java

@Namespace('/')@ParentPackage('struts-default')@Controllerpublic class UserAction extends ActionSupport implements ModelDriven<User> { private User user = new User(); public User getModel() {return this.user; } // ***************************** @Autowired private UserService userService; @Action(value = 'userAction_add', results = { @Result(name = 'add', location = '/success.jsp') }) public String add() {this.userService.saveUser(user);return 'add'; }}

UserServiceImpl.java

@Servicepublic class UserServiceImpl implements UserService { @Autowired private UserDao userDao; @Transactional public void saveUser(User user) {this.userDao.save(user); } @Transactional public void updateUser(User user) {this.userDao.update(user); } @Transactional public void deleteUser(User user) {this.userDao.delete(user); } @Transactional(readOnly = true) public User findUserById(Integer id) {return this.userDao.findById(id); } @Transactional(readOnly = true) public List<User> findAllUser() {return this.userDao.findAll(); }}

配置文件

<?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' xmlns:tx='http://www.springframework.org/schema/tx' xmlns:aop='http://www.springframework.org/schema/aop' xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd'> <!-- 掃描 com包--> <context:component-scan base-package='com'></context:component-scan> <context:annotation-config/> <!-- <context:property-placeholder location='classpath:redis.properties'/> <bean class='redis.clients.jedis.JedisPoolConfig'> <property name='maxIdle' value='${redis.pool.maxIdle}' /> <property name='maxTotal' value='${redis.pool.maxActive}' /> <property name='maxWaitMillis' value='${redis.pool.maxWaitMillis}' /> <property name='testOnBorrow' value='${redis.pool.testOnBorrow}' /> <property name='testOnReturn' value='${redis.pool.testOnReturn}' /> </bean> --><!-- 加載c3p0-db.properties --> <context:property-placeholder location='classpath:c3p0-db.properties' /> <!-- 配置dataSource數(shù)據(jù)源 --> <bean class='com.mchange.v2.c3p0.ComboPooledDataSource'><property name='driverClass' value='${jdbc.driverClass}'></property><property name='jdbcUrl' value='${jdbc.jdbcUrl}'></property><property name='user' value='${jdbc.user}'></property><property name='password' value='${jdbc.password}'></property> </bean><!-- 1 配置SessionFactory --> <bean class='org.springframework.orm.hibernate5.LocalSessionFactoryBean'><!-- 1.1 配置數(shù)據(jù)源 --><property name='dataSource' ref='dataSource'></property><!-- 1.2 其他配置項 ,要使用hibernate全屬性名,如果hibernate.不要省略 --><property name='hibernateProperties'> <props><prop key='hibernate.dialect'> org.hibernate.dialect.MySQL5Dialect </prop><prop key='hibernate.show_sql'>true</prop><prop key='hibernate.format_sql'>true</prop><prop key='hibernate.hbm2ddl.auto'>update</prop><prop key='javax.persistence.validation.mode'>none</prop><prop key='hibernate.current_session_context_class'>thread</prop><prop key=''></prop> </props></property><!-- 配置實體類 --><property name='packagesToScan'> <list><value>com.entity</value> </list></property> </bean> <!-- 配置hibernate模板,必須使用模板 --> <bean class='org.springframework.orm.hibernate5.HibernateTemplate'><!-- 通過工廠獲得session,操作PO類 --><property name='sessionFactory' ref='sessionFactory'></property> </bean> <!-- 事務(wù)管理 --> <!-- 事務(wù)管理器,就是平臺,spring工具產(chǎn)生, 依賴于使用 持久方案(hibernate、jdbc等) --> <bean class='org.springframework.orm.hibernate5.HibernateTransactionManager'><property name='sessionFactory' ref='sessionFactory'></property> </bean> <!-- 將事務(wù)管理注冊spring * proxy-target-class='true': 使用cglib * proxy-target-class='false':有接口將使用 jdk --> <tx:annotation-driven transaction-manager='txManager' /></beans>

問題解答

回答1:

請保證UserServiceImpl在被掃描的包內(nèi)。

回答2:

注解的掃描有問題

回答3:

我建議你看看UserDao是否正確注入,這條鏈子上有一個注入失敗了就會導(dǎo)致整體創(chuàng)建失敗

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 成人免费网站视频 | 欧美黄成人免费网站大全 | www久久久| 欧美另类69xxxxx视频 | 老司机黄色影院 | 成人18免费视频 | 91寡妇天天综合久久影院 | 亚洲国产日韩欧美高清片a 亚洲国产日韩欧美在线 | 国产一级片免费 | 一区二区三区中文国产亚洲 | 欧美成性色 | 国内自拍网红在线综合 | 久久青草国产手机看片福利盒子 | 亚洲第一视频在线播放 | 欧美性猛交xxxxx按摩国内 | a级片在线免费看 | 亚洲性无码av在线 | 免费观看欧美精品成人毛片 | 一区二区网站在线观看 | 777色狠狠一区二区三区 | 日韩一区三区 | 欧美一级网址 | 久草久草在线视频 | 国产高清精品毛片基地 | 国产精品路边足疗店按摩 | 俄罗斯18videosex性欧美成人 | 影院成人区精品一区二区婷婷丽春院影视 | 久久福利青草精品资源站免费 | 精品视频自拍 | 国产美女一区精品福利视频 | 成人五级毛片免费播放 | 欧美视频精品一区二区三区 | 国产成在线观看免费视频成本人 | 成人区视频爽爽爽爽爽 | 毛片a级三毛片免费播放 | 伊人一级 | 欧美牲 | 欧美精品久久久久久久久大尺度 | 国产人成 | 欧美精品毛片 | 色综合a怡红院怡红院首页 色综合精品久久久久久久 色综合九九 |