这个错误是什么意思,怎么处理?重来没见过呀
og4j:WARN No appenders could be found for logger (org.springframework.context.support.FileSystemXmlApplicationContext).log4j:WARN Please initialize the log4j system properly.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/Administrator/AppData/Local/Genuitec/Common/plugins/com.genuitec.org.hibernate.eclipse_3.2.4.CR1-me201003101716/myeclipse-data/3.3/lib/required/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Administrator/Workspaces/MyEclipse%208.5/myEdition/WebRoot/WEB-INF/lib/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Exception in thread "main" java.lang.ClassCastException: org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator cannot be cast to com.myEdition.dao.UserDAO
at com.myEdition.action.RegeditAction.main(RegeditAction.java:89)
------------------------------------------------------------------------------------------------
下面是配置:
<?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" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-p-3.0.xsd
">
<!-- 启用自动扫描
<context:component-scan base-package="com.myEdition"></context:component-scan> -->
<!-- 事务管理 -->
<!-- 以下的被注释
<tx:annotation-driven transaction-manager="transactionManger"/>
<bean id="transactionManger" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
-->
<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>
</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="get*"> PROPAGATION_REQUIRED</prop>
<prop key="*"> PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- 定义BeanNameAutoProxyCreator,该bean是个bean后处理器,无需被引用,因此没有id属性
这个bean后处理器,根据事务易做图为目标bean自动创建事务代理-->
<bean id="userDAOProxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 指定哪些bean自动生成业务代理 -->
<property name="beanNames">
<!-- 下面是所有需要自动创建事务代理的bean-->
<list>
<value>UserDAO</value>
<value></value>
<value></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>
<!-- spring容器管理业务逻辑层service -->
<bean id="Regeditlmpl" class="com.myEdition.domain.impl.Regeditlmpl">
<property name="UserDAO" ref="UserDAO"></property>
</bean>
<!-- spring容器管理action -->
<bean id="RegeditAction" class="com.myEdition.action.RegeditAction">
<property name="Regeditlmpl" ref="Regeditlmpl"></property>
</bean>
</beans>
--------------------编程问答-------------------- 1、log4j初始化出错。
2、类型转换出错 --------------------编程问答-------------------- 缺少log4j的jar,好像程序写的也有问题 --------------------编程问答-------------------- 应该怎么转换呢?老师让教作业,我不会弄这个,求指导啊。。。。 --------------------编程问答-------------------- package com.myEdition.action;
import java.sql.SQLException;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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;
@SuppressWarnings("serial")
@Controller("RegeditAction")
@Scope("prototype")
public class RegeditAction extends ActionSupport {
//定义接口Regedit
@Resource
private User user;
private Regeditlmpl RegeditImpl;
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public User getUser(){
return user;
}
public void setUser(User user){
this.user=user;
}
public User reg(String username,String password){
user.setPassword(password);
user.setUsername(username);
return user;
}
public String execute(){
//保存用户提交的信息
User user1 = RegeditImpl.find(user.getPassword(), user.getUsername());
if(user!=null){
Map session=(Map)ActionContext.getContext().getSession();
session.put("user1", user1);
RegeditImpl.saveUser(user);
return "regedit";
//返回页面
}
else return null;
}
/*
public String regedit(){
System.out.println(user.getUsername());
User user1=new User();
user1.setId(user.getId());
user1.setPassword(user.getPassword());
user1.setUsername(user.getUsername());
regedit.saveUser(user1);
return "regedit";
}*/
public Regeditlmpl getRegeditImpl() {
return RegeditImpl;
}
public void setRegeditImpl(Regeditlmpl regeditImpl) {
RegeditImpl = regeditImpl;
}
public static void main(String[]args){
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");
User user2 = new User();
user2.setId(1);
user2.setPassword("456");
user2.setUsername("zzq");
UserDAO userDao = (UserDAO)context.getBean("userDAOProxy");
userDao.insert(user2);
}
}
--------------------编程问答--------------------
UserDAO userDao = (UserDAO)context.getBean("userDAOProxy");
你定义的userDAOProxy这个bean的class是UserDAO吗?
如果是,那么你定义的bean在spring配置文件中应该有下面的这条配置:
<bean id="userDAOProxy" class="com.myEdition.dao.UserDAO"></bean>
如果你没有在applicationContext.xml中定义上面的bean,那么你就得代码就需要修改为:
UserDAO userDao = context.getBean(UserDao.class);
补充:Java , Java EE