首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

为什么么会是null?

2013-12-28 
为何么会是null???我已经注入了,打断点发现regedit为null,这是什么情况????xml version1.0 encoding

为何么会是null???
我已经注入了,打断点发现regedit为null,这是什么情况???

<?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:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">




<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/myedition">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"></ref>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
 <prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
  <value>com/myEdition/bean/Content.hbm.xml</value>
 <value>com/myEdition/bean/ContentType.hbm.xml</value>  
 <value>com/myEdition/bean/User.hbm.xml</value>  
</list>
</property>
  <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /> 
</bean>


 
 <!-- 定义事务管理器(声明式的事务) -->  
 <bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>



<!-- 配置事务拦截器 -->
<bean id="transactionInterceptor"  class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!--事务拦截器BEAN需要依赖注入一个事物管理器 -->
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<!-- 定义事物传播属性 -->
<props>
<prop key="delete*"> PROPAGATION_REQUIRED</prop>
<prop key="insert*"> PROPAGATION_REQUIRED</prop>
<prop key="update*"> PROPAGATION_REQUIRED</prop>
<prop key="save*"> PROPAGATION_REQUIRED</prop>
<prop key="find*"> PROPAGATION_REQUIRED</prop>

<prop key="*"> PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>


<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 指定哪些bean自动生成业务代理 -->



<property name="beanNames">

<list>
<value>Regedit</value>
<value>setContentType</value>
<value>Edit</value>
</list>
</property>
<!--   下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>

</list>
</property>
</bean>

 <!--spring beanName dao层的beanName -->
   <bean id="userDAO" class="com.myEdition.dao.impl.UserDAOImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>

  <bean id="contentTypeDAO" class="com.myEdition.dao.impl.ContentTypeDAOImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 
 <bean id="contentDAO" class="com.myEdition.dao.impl.ContentDAOImpl">
 <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 
 <!-- spring容器管理业务逻辑层service -->
  <bean id="Regedit" class="com.myEdition.domain.impl.Regeditlmpl">
 <property name="userDAO" ref="userDAO"></property>
 </bean>
 
 <bean id="setContentType" class="com.myEdition.domain.impl.SetContentTypeImpl">
 <property name="contentTypeDAO" ref="contentTypeDAO"></property>


 </bean>
 <bean id="Edit" class="com.myEdition.domain.impl.EditImpl">
 <property name="contentDAO" ref="contentDAO"></property>
 </bean>
 
 
 
</beans>

---------------------------------------------------------------------------------------------
package com.myEdition.action;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;

import com.myEdition.bean.User;
import com.myEdition.dao.UserDAO;
import com.myEdition.dao.impl.UserDAOImpl;
import com.myEdition.domain.Regedit;
import com.myEdition.domain.impl.Regeditlmpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class RegeditAction extends ActionSupport {

//定义接口Regedit

private String username;
private String password;
private User user;

private Regedit regedit;




public Regedit getRegedit() {
return regedit;
}

public void setRegedit(Regedit regedit) {
this.regedit = regedit;
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}





public void setUsername(String username) {
this.username = username;
}

 public String getUsername() {
return username;
}



public void setPassword(String password) {
this.password = password;
}


public String getPassword() {
return password;
}



public String execute(){
//保存用户提交的信息


User user1= new User();
user1.setPassword(password);
user1.setUsername(username);

regedit.saveUser(user1);


return "sucesss";
//返回页面


}







}

regedit.saveUser(user1);打断点我发现regedit 为null,这是什么情况?
[解决办法]
<bean id="Regedit" class="com.myEdition.domain.impl.Regeditlmpl">
  <property name="userDAO" ref="userDAO"></property>
  </bean>
spring中定义的ID跟你类中定义的名称不一样!注意大小写!
private Regedit regedit;

热点排行