如题:
##Application配置文件##
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@127.0.0.1:1521:ORCL">
</property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/play/Bean/Area.hbm.xml</value></list>
</property></bean>
<bean id="AreaDAO" class="com.play.IDaoImpl.AreaDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="IAreaService" class="com.play.IServiceImpl.IAreaServiceImpl">
<property name="iAreaDao">
<ref bean="AreaDAO" />
</property>
</bean>
<bean id="AreaAction" class="com.play.Action.AreaAction">
<property name="areaService">
<ref bean="IAreaService" />
</property>
</bean>
</beans>##Action类##
package com.play.Action;import com.opensymphony.xwork2.ActionSupport;
import com.play.Bean.Area;
import com.play.IService.IAreaService;public class AreaAction extends ActionSupport{
public Area area;
public IAreaService areaService;
public String addArea()
{
areaService.addArea(area);
return "success";
}
public Area getArea() {
return area;
} public void setArea(Area area) {
this.area = area;
} public IAreaService getAreaService() {
return areaService;
} public void setAreaService(IAreaService areaService) {
this.areaService = areaService;
}
}程序运行起来,Action在执行addArea方法的时候,areaService对象为空,这个为什么呢?.是还有哪里需要配置还是什么问题?
##Application配置文件##
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@127.0.0.1:1521:ORCL">
</property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/play/Bean/Area.hbm.xml</value></list>
</property></bean>
<bean id="AreaDAO" class="com.play.IDaoImpl.AreaDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="IAreaService" class="com.play.IServiceImpl.IAreaServiceImpl">
<property name="iAreaDao">
<ref bean="AreaDAO" />
</property>
</bean>
<bean id="AreaAction" class="com.play.Action.AreaAction">
<property name="areaService">
<ref bean="IAreaService" />
</property>
</bean>
</beans>##Action类##
package com.play.Action;import com.opensymphony.xwork2.ActionSupport;
import com.play.Bean.Area;
import com.play.IService.IAreaService;public class AreaAction extends ActionSupport{
public Area area;
public IAreaService areaService;
public String addArea()
{
areaService.addArea(area);
return "success";
}
public Area getArea() {
return area;
} public void setArea(Area area) {
this.area = area;
} public IAreaService getAreaService() {
return areaService;
} public void setAreaService(IAreaService areaService) {
this.areaService = areaService;
}
}程序运行起来,Action在执行addArea方法的时候,areaService对象为空,这个为什么呢?.是还有哪里需要配置还是什么问题?
解决方案 »
- 十万火急!!!mysql-ds.xml在jboss5中怎么配置?
- tomcat下连接池中存在的疑问
- HELP!以下随机移动图片代码为什么无效?
- 我想在TOMCAT关闭的时候做一些操作,请问能否实现
- insert into 的简单问题。大家帮我看看
- java.lang.NoClassDefFoundError: com/sun/faces/spi/InjectionPro异常
- 编译出错!!!!must be caught or declared to be thrown请帮忙看看!!!
- 简单的代码 但是没有达到目的 请高手看看
- 怎样自动登录?高手赐教!!——不知技术是否可以实现?
- JSP的树的问题
- JSP中文乱码问题
- 大家觉得javaweb整合开发王者归来怎么样!
<bean id="IAreaService" class="com.play.IServiceImpl.IAreaServiceImpl">
<property name="iAreaDao">
<ref bean="AreaDAO" />
</property>
</bean>id="IAreaService" 改为 id="areaService"
System.out.println("-------------------------") ;//看看 有没有信息出来
this.areaService = areaService;
}
属性定义都是private的,不知道是不是这个原因。
不知道。
你要先确定到底哪个为空?一步步,首先,debug,首先确认dao中,dataSource注入成功,再确认service中,dao注入成功。
汗!你得好好学学Spring的注入...
<context:component-scan base-package="com" />
如果解决了,告诉我一下。
1.配置文件中的内容不规范 (spring的规范是第一个字符实现小写,其他的字符随便(随便不是说都可以大写))
2.类写的不规范
<bean id="IAreaService" class="com.play.IServiceImpl.IAreaServiceImpl">
这个表示IServiceImpl的内部类 还是什么 我认为你肯定是包
把上面的修正了应该就能解决你的问题。spring的注入式没有问题的
如果以上方法解决了。你再试试给个bean叫一个全大写的 spring也是注入不成功.