spring 注入失败

ding82727 ding82727 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/profiles/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>


<display-name>CloudServpage</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

applicationContext.xml
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- Definition of View Resolver -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/WEB-INF/web/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>

<!-- 定义映射 -->
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="login.do">loginAction</prop>
<prop key="userList.do">loginAction</prop>
<prop key="addUser.do">loginAction</prop>
<prop key="updateUser.do">loginAction</prop>

<prop key="roleList.do">roleAction</prop>
<prop key="addRole.do">roleAction</prop>

<prop key="houseList.do">houseAction</prop>
<prop key="addHouse.do">houseAction</prop>
<prop key="updateHouse.do">houseAction</prop>
</props>
</property>

</bean>

<!-- 定义控制器 -->
<bean id="loginAction" class="com.cloud.action.LoginAction"></bean>
<bean id="roleAction" class="com.cloud.action.RoleAction"></bean>
<bean id="houseAction" class="com.cloud.action.HouseAction"></bean>

</beans>

applicationContext-ibatis.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- spring 整和ibatis spring的配置 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

<!-- jndi数据源配置 -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/CloudServpage</value>
</property>
</bean>

<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<!-- 配置事务通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="create*" rollback-for="Exception" />
<tx:method name="delete*" rollback-for="Exception" />
<tx:method name="save*" rollback-for="Exception" />
<tx:method name="insert*" rollback-for="Exception" />
<tx:method name="update*" rollback-for="Exception" />
<tx:method name="del*" rollback-for="Exception" />
<tx:method name="cost*" rollback-for="Exception" />
<tx:method name="add*" rollback-for="Exception"/>
<tx:method name="modify*" rollback-for="Exception"/>
<tx:method name="remove*" rollback-for="Exception"/>
<tx:method name="*" read-only="true" rollback-for="Exception" />
</tx:attributes>
</tx:advice>

<!-- 事物配置 -->
<aop:config>
<aop:pointcut id="operation" expression="execution(* com.cloud.business.*.*(..))" />
<aop:advisor pointcut-ref="operation" advice-ref="txAdvice" />
</aop:config>



<!-- 配置iBatis的sqlMapClient 下面的 springSqlMapConfig.xml 是指定用来与spring整合的ibatis的配置文件
用来与spring整合的ibatis的配置文件的配置内容与单独使用ibatis时的配置 有所不同。详见具体的ibatis配置文件 -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="configLocation">
<value>classpath:springSqlMapConfig.xml</value>
</property>
</bean>

<!-- 根据sqlMapClien获取一个SqlMapClient模版-->
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>

<!-- 添加ibatis支持 抽象类 -->
<bean id="sqlMapClientDaoSupport"
class="org.springframework.orm.ibatis.support.SqlMapClientDaoSupport"
abstract="true">
<property name="dataSource" ref="dataSource"></property>
<property name="sqlMapClient" ref="sqlMapClient"></property>
<property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"></property>
</bean>

</beans>

applicationContext-beans.xml
<?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:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- dao -->
<bean id="housedao" class="com.cloud.dao.SysHouseDAOImpl" parent="sqlMapClientDaoSupport">
</bean>

<!-- business -->
<bean id="housebusiness" class="com.cloud.business.HouseBusinessImpl">
<property name="housedao" ref="housedao" />
</bean>

<!-- Action Definition -->
<bean id="loginAction" class="com.cloud.action.LoginAction">
<property name="housebusiness" ref="housebusiness" />
</bean>


</beans>

以上是我的spring配置文件
下面是action 使用 对象时,发现对象没有注入,HouseBusiness为null。
public class LoginAction extends MultiActionController {

private HouseBusiness housebusiness;

public HouseBusiness getHousebusiness() {
return housebusiness;
}

public void setHousebusiness(HouseBusiness housebusiness) {
this.housebusiness = housebusiness;
}

ibatis也注入失败
严重: Servlet.service() for servlet dispatcherServlet threw exception
java.lang.IllegalArgumentException: No SqlMapClient specified
...全文

相关推荐

评论 19
收藏 已收藏
分享
返回顶部
ding82727
Web 开发 81,108 成员 341,721 内容