ssh配置时。在xml里配置注入sessionfactory失败。而用@Resource注解的方式配置成功

ssh配置时。在xml里配置注入sessionfactory失败。而用@Resource注解的方式配置sessionfactory却可以成功。这是为什么?

<!--配置报错-->

public class BaseServiceImpl implements BaseServiceInter {
@Resource
private SessionFactory sessionFactory;//这样配置不会报错。

public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
}
public Object findById(Class clazz, Serializable id) {
    // TODO Auto-generated method stub
    return sessionFactory.getCurrentSession().get(clazz, id);
}
//统一的查询方法
public List executeQuery(String hql, Object[] paramters) {
    // TODO Auto-generated method stub
    Session session = sessionFactory.openSession();
    System.out.println("111111111");
    Query query = session.createQuery(hql);
    if(paramters != null && paramters.length>0){
        for(int i = 0; i<paramters.length;i++){
            query.setParameter(i, paramters[i]);
        }
    }
    List list=query.list();
    return list;
}

}

1个回答

ssh的配置一搜一大把,仔细对照下看是哪里写错了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
用spring注入sessionfactory,总是null,请教大家帮我看看是什么问题
用ssh做的一个小东西,写了泛型dao,然后继承了hibernatedaosupport,然而 在方法里面用getHibnerateTemplate()时总是null。 我用main方法测试都是成功注入的,还有在其它地方自己new一个然后传入sessionFactory,输出sessionFactory和getHibneratemTemplate都是有值的,但是进入方法总是null,我试了一天都解决不了。 前提:我的所有包都引入好了,包括互相协调的包,由于太多,我就贴了一些相关的方法代码,请大家帮我看看。 另外,还有没有更好的写法?或者比hibernateDaoSupport更好用的模板,有的话,请指点一下,谢谢 这个是BaseDao public interface BaseDao<T extends Serializable , ID extends Serializable> { void save(T entity); void update(T entity); List<T> findAll(Class<T> entityClass); ``` ``` 这是BaseDaoImpl public class BaseDaoImpl<T extends Serializable , ID extends Serializable> extends HibernateDaoSupport implements BaseDao<T, ID> { @Override public void save(T entity) { getHibernateTemplate().save(entity); } @Override public void update(T entity) { getHibernateTemplate().update(entity); @Override public List<T> findAll(Class<T> entityClass) { String hql = "from " + entityClass; System.out.println("template---"+getHibernateTemplate()); System.out.println("hql---"+hql); System.out.println("sessionFactory---"+super.getSessionFactory()); return (List<T>)getHibernateTemplate().find(hql); } ``` ``` 这是BaseService public interface BaseService<T extends Serializable , ID extends Serializable> { void save(T entity); void update(T entity); List<T> findAll(Class<T> entityClass); ``` ``` 这是BaseServiceImpl public class BaseServiceImpl<T extends Serializable , ID extends Serializable> implements BaseService<T, ID> { private BaseDao<T , ID> baseDao; public void setBaseDao(BaseDao<T , ID> baseDao){ this.baseDao = baseDao; } @Override public void save(T entity) { baseDao.save(entity); } @Override public void update(T entity) { baseDao.update(entity); } @Override public List<T> findAll(Class<T> entityClass) { return baseDao.findAll(entityClass); } ``` ``` 这是web.xml <filter> <filter-name>Struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>Struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> ``` ``` 这是applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd"> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean> <bean id="baseDaoImpl" class="com.lamp.dao.impl.BaseDaoImpl"> <property name="sessionFactory" ref="sessionFactory"/> </bean> ```<bean name="showAllContactAction" class="com.lamp.action.ShowAllContactAction" scope="prototype"> <property name="contactServiceImpl"> <bean class="com.lamp.service.impl.ContactServiceImpl"></bean> </property> </bean> ``` 这是action的代码 public class ShowAllContactAction extends ActionSupport{ private List<Contact> resultAllContactList; private ContactServiceImpl contactServiceImpl; public void setContactServiceImpl(ContactServiceImpl contactServiceImpl){ this.contactServiceImpl = contactServiceImpl; } public String execute(){ resultAllContactList = contactServiceImpl.findAll(Contact.class); ActionContext.getContext().put("resultAllContactList" , resultAllContactList); return "SUCCESS"; } } ``` ``` 这是hibernate配置文件 <hibernate-configuration> <session-factory> <property name="show_sql">true</property> <property name="connection.url">jdbc:mysql://localhost:3306/sanke_daily</property> <property name="connection.username">root</property> <property name="connection.password">root</property> <property name="driver_class">com.mysql.jdbc.Driver</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <mapping resource="com/lamp/entity/Contact.hbm.xml"/> </session-factory> </hibernate-configuration> 这是struts.xml <action name="showAllContactAction" class="showAllContactAction"> <result name="SUCCESS">/jsp/contact/showAllContactSuccess.jsp</result> </action> 另外,ContactBaseDao、ContactBaseDaoImpl和ContactService、ContactServiceImpl都没有新加的特别的方法,所以都是空的
报错'sessionFactory' or 'hibernateTemplate' is required,但是spring里已经配置注入
部分错误提示 java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:118) at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485) ... 42 more spring整个配置文件 <?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" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="com.mysql.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql:///news2?characterEncoding=utf-8"></property> <property name="user" value="root"></property> <property name="password" value="1234"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocations" value="classpath:hibernate.cfg.xml"></property> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 事务管理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 事务管理驱动 --> <tx:annotation-driven transaction-manager="transactionManager"/> <bean id="catalogDAO" class="com.lfy.dao.impl.CatalogDAOImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="articleDAO" class="com.lfy.dao.impl.ArticleDAOImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="catalogService" class="com.lfy.service.impl.CatalogServiceImpl"> <property name="catalogDAO" ref="catalogDAO" /> </bean> <bean id="articleService" class="com.lfy.service.impl.ArticleServiceImpl"> <property name="articleDAO" ref="articleDAO" /> </bean> <bean id="catalogAction" class="com.lfy.action.CatalogAction" scope="prototype"> <property name="catalogService" ref="catalogService" /> </bean> <bean id="articleAction" class="com.lfy.action.ArticleAction" scope="prototype"> <property name="articleService" ref="articleService" /> </bean> <bean id="indexAction" class="com.lfy.action.IndexAction" scope="prototype"> <property name="catalogService" ref="catalogService" /> </bean> </beans> DAO实现类 public class ArticleDAOImpl extends HibernateDaoSupport implements ArticleDAO { public List<Article> findall() { String hql="from Article"; List<Article> articles=this.getHibernateTemplate().find(hql); return articles; } } 配置hibernate mapping的时候没有问题,可以自动建表,一加上DAO操作就会报 java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required 不知道是哪里错误,用了能够成功的项目的spring配置文件也会报同样错误,没有C币了可以帮忙看一看吗?
SSH整合过程中:service老是注入失败?
action对象是用struts2产生的,但是service老是注入失败,其他的dao注入正常,在action中通过getbean的方式可以正常获得service 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: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-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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <context:annotation-config /> <!-- 分散配置(配置配置文件的位置) --> <context:property-placeholder location= "classpath:jdbc.properties"/> <!-- 生成实例对象要扫描的包,扫描该包,将该包下的注解@Component的类实例化 --> <context:component-scan base-package="com.slg.surveypark.dao.impl,com.slg.surveypark.service.impl,com.slg.surveypark.struts2.action" /> <!-- 配置数据源 --> <bean id="dataSource" destroy-method="close" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driverClassName}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="maxPoolSize" value="${c3p0.pool.size.max}"/> <property name="minPoolSize" value="${c3p0.pool.size.min}"/> <property name="initialPoolSize" value="${c3p0.pool.size.ini}"/> <property name="acquireIncrement" value="${c3p0.pool.size.increment}"/> </bean> <!--本地会话工程(spring整合 hibernate配置) --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 扫描一下包内的实体类,有@Entity注解与数据库形成映射 --> <property name="packagesToScan"> <list> <value>com.slg.surveypark.model</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <!-- hibernate.hbm2ddl.auto 当为update时根据java对象生成数据库里的表 --> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <aop:config> <aop:pointcut id="bussinessService" expression="execution(* *..*Service.*(..))" /> <aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- 写操作 --> <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"/> <tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT"/> <tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT"/> <tx:method name="batch*" propagation="REQUIRED" isolation="DEFAULT"/> <!-- 读操作 --> <tx:method name="load*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/> <tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/> <tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/> <tx:method name="*" propagation="REQUIRED" isolation="DEFAULT" /> </tx:attributes> </tx:advice> </beans> ``` struts.xml ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- 主题 --> <constant name="struts.ui.theme" value="simple" /> <!-- 开发模式 --> <constant name="struts.devMode" value="true" /> <package name="surveypark" namespace="/" extends="struts-default"> <action name="RegAction_*" class="com.slg.surveypark.struts2.action.RegAction" method="{1}"> <result name="regPage">/reg.jsp</result> <result name="input">/reg.jsp</result> <result name="success">/index.jsp</result> </action> </package> </struts> ``` action类 ``` package com.slg.surveypark.struts2.action; import javax.annotation.Resource; import org.apache.struts2.interceptor.validation.SkipValidation; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Scope; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.stereotype.Component; import com.slg.surveypark.model.User; import com.slg.surveypark.service.UserService; import com.slg.surveypark.service.impl.UserServiceImpl; import com.slg.surveypark.util.ValidateUtil; //@Component("regaction") //@Scope("prototype") //@Controller public class RegAction extends BaseAction<User> { /** * */ private static final long serialVersionUID = 1L; private User model = new User(); private String confirmPassword; public String getConfirmPassword() { return confirmPassword; } public void setConfirmPassword(String confirmPassword) { this.confirmPassword = confirmPassword; } protected UserService userService; public UserService getUserService() { return userService; } @Resource(name="userService") public void setUserService(UserService userService) { this.userService = userService; } @Override public User getModel() { // TODO Auto-generated method stub return model; } /** * * 这里添加了注解 @SkipValidation 所以会跳过默认的拦截器函数validate() */ @SkipValidation public String toRegPage(){ return "regPage"; } public String doReg(){ userService.saveEntity(model); return SUCCESS; } /** * struts2的默认验证拦截器,所有的action执行前都会执行此函数,除非有跳过注解,如果验证过程有有问题,则 * 终端action的执行过程,返回到struts2配置的“input”指向的页面 */ public void validate(){ if(!ValidateUtil.isValid(model.getEmail())){ addFieldError("email", "email是必填项!"); } if(!ValidateUtil.isValid(model.getNickName())){ addFieldError("nickname", "nickname是必填项!"); } if(!ValidateUtil.isValid(model.getPassword())){ addFieldError("password", "password是必填项!"); } if(hasErrors()){ return ; } if(!model.getPassword().equals(confirmPassword)){ addFieldError("password", "密码不一致!"); return ; } //通过getBean可以获得service // ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml"); // userService = (UserService)ctx.getBean("userService"); System.out.println(userService); if(userService.isRegisted(model.getEmail())){ addFieldError("email", "email已占用!"); return; } } } ``` service类 ``` package com.slg.surveypark.service.impl; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import com.slg.surveypark.dao.BaseDao; import com.slg.surveypark.model.User; import com.slg.surveypark.service.UserService; import com.slg.surveypark.util.ValidateUtil; @Component("userService") public class UserServiceImpl extends BaseServiceImpl<User> implements UserService { @Resource(name="userDao") public void setDao(BaseDao<User> dao) { super.setDao(dao); } /** * 判断email是否被注册过 */ public boolean isRegisted(String email){ String hql = "select email from User where email =?"; List<User> users = this.findEntityByHQL(hql, email); return ValidateUtil.isValid(users); } } ``` 求指教
SSH整合 配置文件报错
这是报错 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myaction' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'cn.jbit.ssh.service.impl.PoitestServiceImpl$$EnhancerByCGLIB$$53789971' to required type 'cn.jbit.ssh.service.PoitestService' for property 'ps'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [cn.jbit.ssh.service.impl.PoitestServiceImpl$$EnhancerByCGLIB$$53789971] to required type [cn.jbit.ssh.service.PoitestService] for property 'ps': no matching editors or conversion strategy found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4961) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5455) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3976) at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:426) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519) at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'cn.jbit.ssh.service.impl.PoitestServiceImpl$$EnhancerByCGLIB$$53789971' to required type 'cn.jbit.ssh.service.PoitestService' for property 'ps'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [cn.jbit.ssh.service.impl.PoitestServiceImpl$$EnhancerByCGLIB$$53789971] to required type [cn.jbit.ssh.service.PoitestService] for property 'ps': no matching editors or conversion strategy found at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:485) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:516) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:510) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1406) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1365) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ... 22 more Caused by: java.lang.IllegalStateException: Cannot convert value of type [cn.jbit.ssh.service.impl.PoitestServiceImpl$$EnhancerByCGLIB$$53789971] to required type [cn.jbit.ssh.service.PoitestService] for property 'ps': no matching editors or conversion strategy found at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:241) at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470) ... 28 more 这是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.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="org.postgresql.Driver" /> <property name="url" value="jdbc:postgresql://172.23.144.242:5432/poi2016q4" /> <property name="username" value="test" /> <property name="password" value="test" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="myDataSource" /><!-- 数据源 --> <property name="mappingResources"> <list> <value>cn/jbit/ssh/entity/Poitest.hbm.xml</value> <value>cn/jbit/ssh/entity/Kind.hbm.xml</value> <value>cn/jbit/ssh/entity/Xzqh.hbm.xml</value> <value>cn/jbit/ssh/entity/Chain.hbm.xml</value> <value>cn/jbit/ssh/entity/Foodtype.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.Oracle9iDialect </value> </property> </bean> <!--声明事务 --> <!-- 创建事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 织入增强 --> <aop:config proxy-target-class="true"> <aop:pointcut id="mypoint" expression="execution(* cn.jbit.ssh.service..*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="mypoint" /> </aop:config> <!-- 定义事务 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="find*" read-only="true"/> <tx:method name="one*" read-only="true"/> <tx:method name="*" propagation="SUPPORTS" read-only="true" /> </tx:attributes> </tx:advice> <!-- 接口注入 --> <bean id="mydao" class="cn.jbit.ssh.dao.impl.KindDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="mydao1" class="cn.jbit.ssh.dao.impl.FoodtypeDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="mydao2" class="cn.jbit.ssh.dao.impl.XzqhDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="mydao3" class="cn.jbit.ssh.dao.impl.ChainDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="mydao5" class="cn.jbit.ssh.dao.impl.PoitestDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- service --> <bean id="myservice" class="cn.jbit.ssh.service.impl.KindServiceImpl"> <property name="dao" ref="mydao"></property> </bean> <bean id="myservice1" class="cn.jbit.ssh.service.impl.FoodtypeServiceImpl"> <property name="dao" ref="mydao1"></property> </bean> <bean id="myservice2" class="cn.jbit.ssh.service.impl.XzqhServiceImpl"> <property name="dao" ref="mydao2"></property> </bean> <bean id="myservice3" class="cn.jbit.ssh.service.impl.ChainServiceImpl"> <property name="dao" ref="mydao3"></property> </bean> <bean id="myservice5" class="cn.jbit.ssh.service.impl.PoitestServiceImpl"> <property name="dao" ref="mydao5"></property> </bean> <!-- action --> <bean id="myaction" class="cn.jbit.ssh.action.KindAction"> <property name="ks" ref="myservice"></property> <property name="fs" ref="myservice1"></property> <property name="xs" ref="myservice2"></property> <property name="cs" ref="myservice3"></property> <property name="ps" ref="myservice5"></property> </bean> </beans>
SSH框架中Spring的依赖注入问题
我做了一个struts+hibernate3+spring的整合,我applicationContext .xml文件中已经配置了 <bean id="userDao" class="com.dto.UserDao"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="loginAction" class="com.web.LoginAction"> <property name="userDao" ref="userDao"></property> </bean> 并且在LoginAction中设置的userDao变量和set和get方法,但是运行的时候userDao为空,我已经加入struts-spring-plugin- xx.jar 包,我设断点调试时,在启动tomcate时进入了userDao的set方法,我运行loginAction.action的时候这个userDao却依然为空,请大牛帮忙指点
求助贴,关于SSH的事物管理
假期自己做一个SSH项目,用的是Struts2.3.16.1,Hibernate4.3.4,Spring4.0.2做整合,事务管理用的是每个Bean都有一个代理的方式,在Dao层 private SessionFactory sessionFactory; public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) {log.debug("注入sessionFactory"); this.sessionFactory = sessionFactory; } public Session getSession() { return sessionFactory.getCurrentSession(); } 获得sessionFactory,进行数据库操作时开始报错 List result = getSession().createSQLQuery("SELECT studentId,passWord From student WHERE studentId=1;").list(); 一开始报 : No Session found for current thread ,我在getSession()方法中检查了SessionFactory是有对象的 之后百度了一大堆解决方法,提示我在Hibernate.cfg.xml用current_session_context_class <property name="current_session_context_class">thread</property> 测试,调用getSesion() , 报错:createSQLQuery is not valid without active transaction 换成 <property name="current_session_context_class">jta</property> 依然报错:No TransactionManagerLookup specified 向各位大神求助~~~
搭建简单SSH框架注入问题
很简单的ssh框架整合,搭建好后项目部署没有出错,运行后尝试添加一条数据出现 java.lang.NullPointerException, null spring没有帮我注入,导致accountAction 的accountService为空 找了好久都没有找到问题的根源 以下代码 **IAccount.java【接口】** public interface IAccount { public boolean saveAccount(account account); } **accountDAO【实现类】** package org.asirt.dao.imlp; import org.asirt.dao.IAccount; import org.asirt.entity.account; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; public class accountDAO implements IAccount{ private SessionFactory sessionFactory; public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @Override public boolean saveAccount(account account) { Session session = sessionFactory.openSession(); Transaction ts = session.beginTransaction(); session.save(account); ts.commit(); session.close(); return true; } } **struts.xml 【配置文件】** <struts> <package name="default" extends="struts-default"> <action name="account-go_add" class="org.asirt.action.accountAction" method="go_add"> <result name="go_add">add.html</result> </action> <action name="account-add" class="org.asirt.action.accountAction" method="add"> <result name="success">success.html</result> </action> </package> </struts> **applicationContext.xml【spring配置文件】** <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.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/asirt_bbs?useUnicode=true&amp;characterEncoding=utf-8"> </property> <property name="username" value="root"></property> <property name="password" value=""></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="show_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value>org/asirt/entity/account.hbm.xml</value> </list> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="accountDAO" class="org.asirt.dao.imlp.accountDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="accountAction" class="org.asirt.action.accountAction"> <property name="accountService" ref="accountDAO"></property> </bean> </beans> **accountAction.java【Action】** package org.asirt.action; import org.apache.catalina.User; import org.asirt.dao.IAccount; import org.asirt.entity.account; import com.opensymphony.xwork2.ActionSupport; public class accountAction extends ActionSupport { /** * */ private static final long serialVersionUID = -453090639825021968L; private account account; private IAccount accountService; public String go_add() throws Exception{ return"go_add"; } public String add() throws Exception{ System.out.println(account.getName()); System.out.println(getAccountService()); if(account!=null){ getAccountService().saveAccount(account); System.out.println("hah"); } return"success"; } public account getAccount() { return account; } public void setAccount(account account) { this.account = account; } public IAccount getAccountService() { return accountService; } public void setAccountService(IAccount accountService) { this.accountService = accountService; } }
SSH 整合 当Action切面引入事务管理后,属性无法注入,求大神帮忙看一下
没加入事务切面前,Action中的注入costDao可以注入,可是applicationContext.xml加入了一下配置后 <!-- 声明事务管理,采用AOP形式切入 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- proxy-target-class指定采用cglib机制生成代理类 --> <tx:annotation-driven proxy-target-class="true" transaction-manager="txManager"/> costDao为打印为空指针,即说明无法注入了。这是为什么? 是否是因为类代理啥的影响了注入? Action代码如下 package com.action; import java.util.List; import javax.annotation.Resource; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import com.dao.CostDao; import com.entity.Cost; @Controller @Scope("prototype") @Transactional(readOnly=true) public class FindCostAction { private int page = 1; private int pageSize; @Resource(name="costDao") private CostDao costDao; private List<Cost> costs; private int totalPage; public int getPage() { return page; } public void setPage(int page) { this.page = page; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public int getTotalPage() { return totalPage; } public void setTotalPage(int totalPage) { this.totalPage = totalPage; } public List<Cost> getCosts() { return costs; } public void setCosts(List<Cost> costs) { this.costs = costs; } public String execute(){ System.out.println(page); System.out.println(pageSize); System.out.println(costDao); try { costs = costDao.findByPage(page, pageSize); totalPage = costDao.findTotalPage(pageSize); } catch (Exception e) { e.printStackTrace(); return "error"; }finally{ } return "success"; } public FindCostAction() { super(); System.out.println("costDao:"+costDao); } } 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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation=" http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd 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/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"> <!-- 定义一个连接池 --> <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl"/> <property name="driverClass" value="oracle.jdbc.OracleDriver"/> <property name="user" value="leo"/> <property name="password" value="123"/> <property name="initialPoolSize" value="3"/> <property name="maxPoolSize" value="10"/> <property name="minPoolSize" value="1"/> <property name="acquireIncrement" value="3"/> <property name="maxIdleTime" value="60"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- 指定连接池DataSource --> <property name="dataSource" ref="myDataSource"/> <!-- 指定Hibernate配置参数 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> <!-- 指定hbm.xml文件 --> <property name="mappingResources"> <list> <value>com/entity/Cost.hbm.xml</value> </list> </property> </bean> <!-- 声明事务管理,采用AOP形式切入 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- proxy-target-class指定采用cglib机制生成代理类 --> <tx:annotation-driven proxy-target-class="true" transaction-manager="txManager"/> <!-- 开启注解扫描 --> <context:component-scan base-package="com"/> </beans>
Struts和Spring整合后访问Action注入失败
如题,刚刚接触SSH,不知道是哪配置出问题了, 蛋疼的是单元测试中用ClassPathXmlApplicationContext读取spring配置文件却通过了- - Struts2配置: <struts> <!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 --> <constant name="struts.serve.static.browserCache" value="false" /> <!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 --> <constant name="struts.configuration.xml.reload" value="true" /> <!-- 开发模式下使用,这样可以打印出更详细的错误信息 --> <constant name="struts.devMode" value="true" /> <!-- <constant name="struts.action.extension" value="do,app" /> --> <constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" /> <!-- Configuration for the default package. --> <package name="default" extends="struts-default,json-default"> <action name="*_*" method="{2}" class="org.crush.mlms.action.{1}Action"> <result type="json"> <param name="success">responseJson</param> </result> </action> </package> </struts> Spring配置: <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="url" value="jdbc:mysql://localhost:3306/mlms"></property> <property name="username" value="root"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> </props> </property> <property name="mappingResources"> <list> <value>org/crush/mlms/domain/Test.hbm.xml</value> </list> </property> </bean> <bean id="testAction" class="org.crush.mlms.action.TestAction"> <property name="testService"> <ref bean="TestService" /> </property> <property name="testDao"> <ref bean="testDAO" /> </property> <property name="factory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="testDAO" class="org.crush.mlms.domain.TestDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="TestService" class="org.crush.mlms.service.TestService"> <property name="testDao"> <ref bean="testDAO" /> </property> </bean> web.xml配置: <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>MLMS</display-name> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:Bean.xml</param-value> </context-param> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file> index.html </welcome-file> </welcome-file-list> </web-app>
SSH框架整合中读取不到Spring的配置文件
求大神指导 下面附上源码: 错误提示: 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: entity class not found: po.BizClaimVoucherDetail at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:608) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4853) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: org.hibernate.MappingException: entity class not found: po.BizClaimVoucherDetail at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:125) at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:191) at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:67) at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:135) at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:485) at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:133) at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:286) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:863) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:782) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483) ... 21 more Caused by: java.lang.ClassNotFoundException: po.BizClaimVoucherDetail at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192) at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:122) ... 34 more Spring配置文件的位置在SRC下创建了一个resource的文件夹 applicationContext.xml的配置文件源码: <!-- 创建sessionfactory回话工厂的bean 并读取Hibernate.cfg.xml的配置文件 --> <bean id = "sessionFactory" class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name = "configLocation" value="classpath:Hibernate.cfg.xml"></property> </bean> <!-- 实体类的bean 依赖注入--> <bean id="bizCheckResult" class="com.bdqn.zzt.jboa.entity.BizCheckResult"></bean> <bean id="bizClaimVoucher" class="com.bdqn.zzt.jboa.entity.BizClaimVoucher"></bean> <bean id="bizClaimVoucherDetail" class="com.bdqn.zzt.jboa.entity.BizClaimVoucherDetail"></bean> <bean id="sysDepartment" class="com.bdqn.zzt.jboa.entity.SysDepartment"></bean> <bean id="sysEmployee" class="com.bdqn.zzt.jboa.entity.SysEmployee"></bean> <bean id="sysPosition" class="com.bdqn.zzt.jboa.entity.SysPosition"></bean> <!--数据层的bean 依赖注入 --> <bean id = "userDaoImpl" class = "com.bdqn.zzt.jboa.dao.UserDaoImpl"> <property name = "sessionFactory" ref = "sessionFactory"></property> </bean> <!--业务层的bean 依赖注入 --> <bean id = "userBizImpl" class = "com.bdqn.zzt.jboa.biz.UserBizImpl"> <property name = "userDao" ref = "userDaoImpl"></property> </bean> <!-- 事务的管理 --> <bean id = "transactionManager" class = "org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name = "sessionFactory" ref = "sessionFactory"></property> </bean> <tx:advice id = "txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name = "get*" read-only="false"></tx:method> <tx:method name = "find*" ></tx:method> <tx:method name = "add*" ></tx:method> <tx:method name = "save*" ></tx:method> <tx:method name = "update*" ></tx:method> <tx:method name = "delete*" ></tx:method> <tx:method name = "merge" ></tx:method> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id = "serviceMethod" expression="execution(public * com.bdqn.zzt.jboa.biz.*.*(..))"></aop:pointcut> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"></aop:advisor> </aop:config> Web.xml的源码: <!--Spring 配置文件的存放位置 --> <!-- <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- Spring 的监听器 WEB环境中启动Spring容器 --> <!-- <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!-- OpenSessionInView过滤器的配置 使回sesstion的管理范围增加--> <!-- <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> --> <filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>sessionFactoryBeanName</param-name> <param-value>sessionFactory</param-value> </init-param> </filter> <filter-mapping> <filter-name>openSessionInViewFilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <!--Strurs2的核心过滤器配置 --> <!-- <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
ssh的spring 无法注入怎么回事
<strong>UserInfoDAOImpl.java</strong> <br /><pre name="code" class="java">@Service public class UserInfoDAOImpl extends HibernateDaoSupport implements UserInfoDAO { public boolean login(Userinfo userinfo) { boolean isExist = false; Userinfo temp = (Userinfo)this.getHibernateTemplate().find("from Userinfo u where u.username=?", userinfo.getUsername()).get(0); try { if(userinfo.getPassword().equals(temp.getPassword())) isExist = true; } catch(Exception e) { e.printStackTrace(); } System.out.println("id:" + temp.getId()); System.out.println("username:" + temp.getUsername()); System.out.println("password:" + temp.getPassword()); System.out.println("isExist:" + isExist); return isExist; } }</pre> <br /><strong>LoginAction.java</strong> <br /><pre name="code" class="java">@Component @Results(value={ @Result(name="success", location="/login_success.jsp"), @Result(name="fail", location="/Login.jsp") }) public class LoginAction extends ActionSupport { private Userinfo userinfo; @Autowired private UserInfoDAO userInfoDAOImpl; public Userinfo getUserinfo() { return userinfo; } public void setUserinfo(Userinfo userinfo) { this.userinfo = userinfo; } public UserInfoDAO getUserInfoDAOImpl() { return userInfoDAOImpl; } public void setUserInfoDAOImpl(UserInfoDAO userInfoDAOImpl) { System.out.println("注入"); this.userInfoDAOImpl = userInfoDAOImpl; } @Action("login") public String login() { System.out.println("id:" + userinfo.getId()); System.out.println("username:" + userinfo.getUsername()); System.out.println("password:" + userinfo.getPassword()); if(userInfoDAOImpl == null) System.out.println("error"); if(userinfo == null) return "fail"; else return (userInfoDAOImpl.login(userinfo))?"success":"fail"; } }</pre> <br /><strong>applicationContext.xml</strong> <br /><pre name="code" class="java">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" default-lazy-init="true"&gt; &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /&gt; &lt;property name="ignoreResourceNotFound" value="true" /&gt; &lt;property name="locations"&gt; &lt;list&gt; &lt;value&gt;classpath:application.properties&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;context:component-scan base-package="org.sales.dao.Impl" /&gt; &lt;!-- 数据源配置,使用应用内的DBCP数据库连接池 --&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;!-- Connection Info --&gt; &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt; &lt;property name="url" value="${jdbc.url}" /&gt; &lt;property name="username" value="${jdbc.username}" /&gt; &lt;property name="password" value="${jdbc.password}" /&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="namingStrategy"&gt; &lt;bean class="org.hibernate.cfg.ImprovedNamingStrategy" /&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt; &lt;prop key="hibernate.format_sql"&gt;${hibernate.format_sql}&lt;/prop&gt; &lt;prop key="hibernate.cache.provider_class"&gt;org.hibernate.cache.EhCacheProvider&lt;/prop&gt; &lt;!-- &lt;prop key="hibernate.cache.provider_configuration_file_resource_path"&gt;${hibernate.ehcache_config_file}&lt;/prop&gt;--&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="packagesToScan" value="org.sales.entity" /&gt; &lt;property name="annotatedClasses"&gt; &lt;list&gt; &lt;value&gt;org.sales.entity.Iteminfo&lt;/value&gt; &lt;value&gt;org.sales.entity.Cardinfo&lt;/value&gt; &lt;value&gt;org.sales.entity.Positioninfo&lt;/value&gt; &lt;value&gt;org.sales.entity.Sellinfo&lt;/value&gt; &lt;value&gt;org.sales.entity.Userinfo&lt;/value&gt; &lt;value&gt;org.sales.entity.Voteinfo&lt;/value&gt;&lt;/list&gt; &lt;/property&gt;&lt;/bean&gt; &lt;bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" &gt; &lt;property name="sessionFactory" ref="sessionFactory"/&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory" ref="sessionFactory" /&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt; &lt;bean id="CardinfoDAO" class="org.sales.entity.CardinfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="IteminfoDAO" class="org.sales.entity.IteminfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="PositioninfoDAO" class="org.sales.entity.PositioninfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="SellinfoDAO" class="org.sales.entity.SellinfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="UserinfoDAO" class="org.sales.entity.UserinfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="VoteinfoDAO" class="org.sales.entity.VoteinfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt;</pre> <br /><strong>web.xml</strong> <br /><pre name="code" class="java">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath*:applicationContext.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;filter&gt; &lt;filter-name&gt;OpenSessionInViewFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.orm.hibernate3.support.OpenSessionInViewFilter&lt;/filter-class&gt; &lt;init-param&gt; &lt;param-name&gt;singleSession&lt;/param-name&gt; &lt;param-value&gt;true&lt;/param-value&gt; &lt;/init-param&gt; &lt;/filter&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;filter&gt; &lt;filter-name&gt;struts2Filter&lt;/filter-name&gt; &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;struts2Filter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;OpenSessionInViewFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;/web-app&gt; </pre> <br /> <br />结果在LoginAction.java里面输出: <br />id:null <br />username:username <br />password:USERNAME <br />error <br />说明: error是当被注入的属性为空的时候输出. <br /> 求解~ <br /> <br /><strong>异常(网页上的):</strong> <br />HTTP Status 500 - <br /> <br />type Exception report <br /> <br />message <br /> <br />description The server encountered an internal error () that prevented it from fulfilling this request. <br /> <br />exception <br /> <br />java.lang.NullPointerException <br /> org.sales.actions.LoginAction.login(LoginAction.java:53) <br /> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) <br /> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) <br /> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) <br /> java.lang.reflect.Method.invoke(Method.java:597) <br /> com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) <br /> com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) <br /> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)<br/><strong>问题补充</strong><br/><div class="quote_title">xixix2004 写道</div><div class="quote_div">有异常吗。<br /> <br />敢不敢把异常发出来看一下。</div><br />发了<br/><strong>问题补充</strong><br/><div class="quote_title">xixix2004 写道</div><div class="quote_div">好吧,应该不需要异常,请把ACTION里定义的DAO的变量名,变得和xml里定义的BEAN ID属性一致。</div><br />xml里面没有对应的bean,因为使用注释<br/><strong>问题补充</strong><br/><div class="quote_title">yyf365 写道</div><div class="quote_div">可能和楼主的应用写法不太相同,请问你其他的service是否能注入成功呢?,不过是否能试试在applicationContext配置文件中的声明方式换一种呢?<br /><br />如:<br />&lt;bean id="UserInfoDAO"<br /> class="UserInfoDAOImp"&gt;<br /> &lt;/bean&gt;<br />这种形式注入,实例化由spring托管,而在action中只对UserInfoDAO的service进行注入呢<br /><br />而如果出了该service无法注入外,其他其余的service都能正常注入使用,那就另想办法了</div><br /> 可是这种方法有点麻烦,我想实现注释注入,xml文件里面有个扫描的:<br /> &lt;context:component-scan base-package="org.sales.dao.Impl" /&gt;&nbsp; <br/><strong>问题补充</strong><br/>已经试过在 <strong>applicationContext.xml</strong> 文件里面添加<br /><pre name="code" class="xml">&lt;bean id="userInfoDAOImpl" class="org.sales.dao.Impl.UserInfoDAOImpl"&gt; &lt;/bean&gt; &lt;bean id="loginAction" class="org.sales.actions.LoginAction"&gt; &lt;property name="userInfoDAOImpl"&gt; &lt;ref bean="userInfoDAOImpl" /&gt; &lt;/property&gt; &lt;/bean&gt;</pre><br /><br />异常信息一样.<br/><strong>问题补充</strong><br/><div class="quote_title">xixix2004 写道</div><div class="quote_div"><div class="quote_title">bbinglongg 写道</div><div class="quote_div"><div class="quote_title">xixix2004 写道</div><div class="quote_div">好吧,应该不需要异常,请把ACTION里定义的DAO的变量名,变得和xml里定义的BEAN ID属性一致。</div><br />xml里面没有对应的bean,因为使用注释</div><br /><br /><br />你完全没看懂我在说什么。<br /><br /><pre name="code" class="java">private UserInfoDAO userinfoDAO; </pre><br /><pre name="code" class="java"> &lt;bean id="userinfoDAO" class="org.sales.entity.UserinfoDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; </pre><br /><br /><br /><br /></div><br />在它上面有一句:<br /><pre name="code" class="java">@Autowired</pre><br />是自动注入的意思<br/><strong>问题补充</strong><br/><div class="quote_title">xixix2004 写道</div><div class="quote_div">&lt;ref bean="UserInfoDAO" /&gt;这里的REF的BEAN, 写你之前定义的BEAN的ID。你可明白?</div><br />明白<br/><strong>问题补充</strong><br/><div class="quote_title">dwbin 写道</div><div class="quote_div">loginAction没有进行spring托管。<br />这个类spring不会自己进行注入的。你的ssh整合有问题</div><br /><br />那我应该怎么修改呢?<br/><strong>问题补充</strong><br/><div class="quote_title">dwbin 写道</div><div class="quote_div">loginAction没有进行spring托管。<br />这个类spring不会自己进行注入的。你的ssh整合有问题</div><br />在 <pre name="code" class="java">@Autowired</pre> 这个标签里面已经是注入了
spring整合hibernate的sessionFactory,报以下错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerServiceImpl' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'customerDaoImpl' of bean class [cn.itcast.ssh.service.impl.CustomerServiceImpl]: Bean property 'customerDaoImpl' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1518) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at cn.itcast.ssh.spring_sessionFactory.Spring_SessionFactory.test(Spring_SessionFactory.java:22) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:292) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'customerDaoImpl' of bean class [cn.itcast.ssh.service.impl.CustomerServiceImpl]: Bean property 'customerDaoImpl' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:231) at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:423) at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514) ... 36 more **spring的配置文件如下**: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- 1.配置查询所有客户的bean对象,注入spring管理的sessionFactory对象 --> <bean id="customerDaoImpl" class="cn.itcast.ssh.dao.impl.CustomerDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="customerServiceImpl" class="cn.itcast.ssh.service.impl.CustomerServiceImpl"> <property name="customerDaoImpl" ref="customerDaoImpl"></property> </bean> <!-- 2.spring管理action的创建和service层注入 --> <bean id="findAllCustomer" class="cn.itcast.ssh.web.action.CustomerAction" scope="prototype"> <property name="customerServiceImpl" ref="customerServiceImpl"></property> </bean> <!-- 3.在spring配置sessionFactory,注入到dao中 ,就是在LocalSessionFactoryBean类中注入一个属性configLocation,其值value就是引用hibernate的sessionFactory--> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> </bean> ** 测试类代码如下** package cn.itcast.ssh.spring_sessionFactory; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import cn.itcast.ssh.domain.Customer; import cn.itcast.ssh.service.CustomerService; import cn.itcast.ssh.service.impl.CustomerServiceImpl; /** * * @author Hongqiankun 测试spring管理sessionFactory的创建,是否能用 1.手动加载spring的配置文件 * 2.获取serviceImpl的bean对象,调用save方法,由于save中使用了sessionFactory * 所以,如果spring没能成功注入sessionFactory,则程序保存,无法将新的客户信息录入到数据库; * */ public class Spring_SessionFactory { @Test public void test() { //1.加载spring的配置文件,获得CustomerServiceImpl对象 ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); CustomerService customerServiceImpl = (CustomerServiceImpl) context.getBean("customerServiceImpl"); //2.创建新的customer Customer cus = new Customer(); cus.setCustName("北方科技2"); cus.setCustAddress("北京"); cus.setCustIndustry("科技公司"); cus.setCustPhone("13214132344"); cus.setCustSource("推广"); cus.setCustLevel("普通客户"); //3.调用saveCustomer方法 customerServiceImpl.saveCustomer(cus); } } </beans>
ssm 整合 service层使用Autowired注入dao 报红,可以使用,为什么?
![图片说明](https://img-ask.csdn.net/upload/201712/11/1512966681_57369.png) ### applicationContext.xml 配置 ```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:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" 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/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"> <!-- 读取数据库配置文件 --> <context:property-placeholder location="classpath:jdbc.properties"/> <!-- 启动上下文的注解配置 --> <context:annotation-config/> <!-- 扫描含有注解的包 --> <context:component-scan base-package="niit.dxs.lehuSSM.service"/> <!-- 配置数据源,使用阿里巴巴的druid数据库连接池 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <!--初始化大小--><property name="initialSize" value="20"/> <!--连接池最大使用连接数量--> <property name="maxActive" value="20"/> <!--连接池最小空闲--> <property name="minIdle" value="0"/> <!--配置获取连接等待超时的时间--> <property name="maxWait" value="60000"/> <!--配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒--> <property name="timeBetweenEvictionRunsMillis" value="60000"/> <!--配置一个连接在池中最小生存的时间,单位是毫秒--> <property name="minEvictableIdleTimeMillis" value="300000"/> <!--连接空闲时测试是否有效--> <property name="testWhileIdle" value="false"/> <!--获取连接时测试是否有效--> <property name="testOnBorrow" value="false"/> <!--归还连接时是否测试有效--> <property name="testOnReturn" value="false"/> <!--打开PSCache缓存,并且指定每个连接上PSCache的大小--> <property name="poolPreparedStatements" value="true"/> <property name="maxPoolPreparedStatementPerConnectionSize" value="20"/> </bean> <!-- 配置 mybatis 的SessionFactory 实例 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 指定数据源 --> <property name="dataSource" ref="dataSource"/> <!-- 指定映射文件位置 --> <property name="mapperLocations" value="classpath*:/niit/dxs/lehuSSM/mapper/*.xml"/> <!-- 指定别名 --> <property name="typeAliasesPackage" value="niit.dxs.lehuSSM.domain"/> </bean> <!--配置DAO接口所在的包--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="niit.dxs.lehuSSM.dao"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> </bean> <!--配置一个事务管理器的bean --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource"/> <!--配置声明式事务,在使用处加注解@Transactional--> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> <!--用于文件上传--> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" p:defaultEncoding="UTF-8" p:maxUploadSize="5242880"/> </beans> ``` ### spring_mvc-servlet.xml 配置 ```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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!--启动MVC注解--> <mvc:annotation-driven/> <!--扫描含有注解的包,(控制器所在的包)--> <context:component-scan base-package="niit.dxs.lehuSSM.controller"/> <!--配置视图解析器,指定视图所在路径,视图文件后缀名--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:viewClass="org.springframework.web.servlet.view.JstlView" p:prefix="/" p:suffix=".jsp"/> <!--保证静态资源不被拦截--> <mvc:default-servlet-handler/> <!-- 拦截器 --> <mvc:interceptors> <mvc:interceptor> <!-- 表示拦截所有 --> <mvc:mapping path="/**"/> <!--<mvc:exclude-mapping path="/css/*.css"/>--> <!-- 指定拦截器 --> <bean class="niit.dxs.lehuSSM.interceptor.LoginInterceptor"/> </mvc:interceptor> </mvc:interceptors> </beans> ``` ### web.xml 配置 ```xml <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <display-name>lehuSSM</display-name> <!--默认启动页--> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- 加载spring容器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml,classpath:spring_mvc-servlet.xml</param-value> </context-param> <!-- 过滤器统一编码 --> <filter> <filter-name>Spring character encoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param><!-- 过滤请求字符集 --> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param><!-- 过滤响应字符集 --> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>Spring character encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- spring容器配置 ,当服务器启动,加载web.xml配置文件--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 控制器 当服务器启动,加载spring_mvc-servlet.xml配置文件--> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring_mvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- mvc控制器映射 --> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app> ```
SSH整合框架,项目启动后控制台报错找不到applicatoinContext.xml里面的类
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.dao.impl.BookDaoImpl] for bean with name 'bookDao' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.dao.impl.BookDaoImpl at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1262) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1331) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:897) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:566) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) ** 提示说找不到这个实现接口类,以下是我的applicationContext.xml里的注入,路径可以点过去** <bean id="bookDao" class="com.dao.impl.BookDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="bookService" class="com.service.impl.BookServiceImpl"> <property name="bookDao" ref="bookDao"></property> </bean> <bean id="bookAction" class="com.action.BookAction"> <property name="bookService" ref="bookService"></property> </bean> 新手,求大神帮忙解答一下.
SSH整合2.0事务配置问题
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [ht.zc.dao.UserDAO] for property 'userDAO'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [ht.zc.dao.UserDAO] for property 'userDAO': no matching editors or conversion strategy found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1303) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1042) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485) at java.security.AccessController.doPrivileged(Native Method) 已经4天了,这个问题还没搞懂,就是事务配置的过程中问题,我的项目大致格式:DAO继承HibernateDaoSupport,service和action都是注入想对应的DAO和service, 下面是applicationContext.xml的配置: <bean id="userDao" class="ht.zc.dao.UserDAO"> <property name="hibernateTemplate" ref="hibernateTemplate" /> <!--改成hinernateSsessFactory,也不行--> </bean> <bean id="userService" class="ht.zc.service.UserService"> <property name="userDAO" ref="userDao" /> </bean> <bean id="transManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory"></ref> </property> </bean> <tx:advice id="bizProxy" transaction-manager="transManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="find*" read-only="true" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="bizMethods" expression="execution(* ht.zc.dao.*.*(..))" /> <aop:advisor advice-ref="bizProxy" pointcut-ref="bizMethods" /> </aop:config> [b]问题补充:[/b] 换成sessionFactory也没用,这些事务配置都是没什么变化,2位提供的方案没用,不知道是不是和这个有关系:Failed to convert property value of type [$Proxy0] to required type [ht.zc.dao.UserDAO] for property 'userDAO'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [ht.zc.dao.UserDAO] for property 'userDAO': no matching editors or conversion strategy found
SSH框架,程序没有报错但是建表不成功,大哥们求助!
applicationContext.xml中的配置: <!-- 引入外部属性文件 --> <context:property-placeholder location="classpath:jdbc.properties"/> <!-- 配置连接池 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driverClass}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="user" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <!-- 配置Hibernate的相关属性 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- 注入连接池 --> <property name="dataSource" ref="dataSource"/> <!-- 配置Hibernate的属性 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> <!-- 加载Hibernate中的映射文件 --> <property name="mappingResources"> <list> <value>com/vicy/ssh/domain/Product.hbm.xml</value> </list> </property> </bean> jdbc.properties中的配置: jdbc.driverClass=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/ssh jdbc.username=root jdbc.password=123 请问哪里配置的不对,求教!!
SSH整合时tomcat服务启动不了
启动tomcat 服务时报 严重: Error listenerStart 2009-4-17 15:05:58 org.apache.catalina.core.StandardContext start 严重: Context [/Test] startup failed due to previous errors 的错误 web.xml配置文件如下: <!-- 配置监听器 配置spring配置文件的加载路径 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- OpenSessionInView 延迟加载的问题 --> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter> <!-- 配置中文字符问题 --> <filter> <filter-name>charfilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>charfilter</param-name> <param-value>UTF-8</param-value> </init-param> </filter> ------------------------------------------------------------------------------------------------- struts-config.xml配置文件如下: <!-- 配置将struts 自动创建的action交给spring处理 --> <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"> </controller> ------------------------------------------------------------------------------------------------- applicationContext.xml配置文件如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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 "> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property> <property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=testdb"></property> <property name="username" value="sa"></property> <property name="password" value="123456"></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.SQLServerDialect</prop> </props> </property> <property name="mappingResources"> <list> <value>com/svse/entity/Student.hbm.xml</value> <value>com/svse/entity/Class.hbm.xml</value> <value>com/svse/entity/Studentinfo.hbm.xml</value> <value>com/svse/entity/Classinfo.hbm.xml</value></list> </property></bean> <bean id="StudentinfoDAO" class="com.svse.dao.StudentinfoDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="ClassinfoDAO" class="com.svse.dao.ClassinfoDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!-- 配置业务层 impl --> <bean id="StudnetImpl" class="com.svse.impl.StudentImpl"> <property name="studao"> <ref bean="StudentinfoDAO"/> </property> </bean> <bean id="ClassImpl" class="com.svse.impl.ClassImpl"> <property name="classdao"> <ref bean="ClassinfoDAO"/> </property> </bean> <!-- 配置action --> <!-- 配置事务 --> <!-- 配置hibernate事务管理器 --> <bean id="MyTrans" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <!-- 配置事务特性 --> <tx:advice id="tx1" transaction-manager="MyTrans"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="del*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <!-- 使用aop 注入 --> <aop:config> <aop:pointcut id="p1" expression="execution(* com.svse.impl.*.*(..))"/> <aop:advisor advice-ref="tx1" pointcut-ref="p1"/> </aop:config> </beans> --------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------- 配置文件信息跟上个练习的项目中无差别,上个项目中也出现过这个文件,但忘了怎么解决的。请老鸟解决下下,谢谢咯 [b]问题补充:[/b] 恩,1楼,把你说的那段代码去掉后不报错。但后面肯定要用到这的,请帮忙解决 [b]问题补充:[/b] java.lang.ClassNotFoundException: org.springframework.scripting.config.LangNamespaceHandler at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205) at org.springframework.util.ClassUtils.forName(ClassUtils.java:229) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.initHandlerMappings(DefaultNamespaceHandlerResolver.java:117) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:96) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:83) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createDefaultNamespaceHandlerResolver(XmlBeanDefinitionReader.java:498) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createReaderContext(XmlBeanDefinitionReader.java:487) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:468) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:363) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:313) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) (4219 ms) [main] DEBUG: org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver#initHandlerMappings : Ignoring namespace handler [org.springframework.ejb.config.JeeNamespaceHandler]: handler class not found java.lang.ClassNotFoundException: org.springframework.ejb.config.JeeNamespaceHandler at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205) at org.springframework.util.ClassUtils.forName(ClassUtils.java:229) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.initHandlerMappings(DefaultNamespaceHandlerResolver.java:117) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:96) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:83) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createDefaultNamespaceHandlerResolver(XmlBeanDefinitionReader.java:498) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createReaderContext(XmlBeanDefinitionReader.java:487) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:468) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:363) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:313) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) [b]问题补充:[/b] 自动代理的bean?我先前练习的好像也是这样陪的 [b]问题补充:[/b] 还有这个 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist Caused by: java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:656) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1198) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1167) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) (5938 ms) [main] ERROR: org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/Test]#listenerStart : Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist Caused by: java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:656) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1198) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1167) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) [b]问题补充:[/b] 有这个包,不少 [b]问题补充:[/b] spring包已经截图 [b]问题补充:[/b] 你说说包的名字吧。 你刚才说的那个包确实有, 要不我直接把项目打包发你给我看看? [b]问题补充:[/b] 我想问下 我的entity 里的配置文件名字是 Studentinfo.hbm.xml 他怎么报 java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist Caused by: java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist 的错误 [b]问题补充:[/b] 问题已解决,就是因为sessionfactory那个bean下有个student。hbm。xml的原因 谢谢你lovewhzlq (资深程序员)
Spring整合hibernate SessionFactoryImpl的问题
各位大侠,本人在整合Spring和Hibernate4时出现了Failed to convert property value of type 'org.hibernate.internal.SessionFactoryImpl' to required type 'org.hibernate.Session' for property 'sessionFactory'问题,我的applicationContext.xml如下: <bean id="employeeDao" class="com.ssh.dao.EmployeeDao"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="employeeService" class="com.ssh.service.EmployeeService"> <property name="employeeDao" ref="employeeDao"></property> </bean> <!-- 配置C3P0数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="user" value="${jdbc.user}"></property> <property name="password" value="${jdbc.password}"></property> <property name="driverClass" value="${jdbc.driverClass}"></property> <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property> <property name="initialPoolSize" value="${jdbc.initPoolSize}"></property> <property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property> </bean> <!-- <context:component-scan base-package="com.ssh.*"></context:component-scan>--> <!-- 配置SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> <property name="mappingLocations" value="classpath:com/ssh/entities/*.hbm.xml"></property> </bean> <!-- 配置xml声明式事务 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="*"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(* com.ssh.service.*.*(..))" id="txPointCut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/> </aop:config> Employee.java: public class EmployeeDao { private SessionFactory sessionFactory; public Session getSessionFactory() { return sessionFactory.getCurrentSession(); } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @SuppressWarnings("unchecked") public List<Employee> getAll(){ String hql = "FROM Employee"; return getSessionFactory().createQuery(hql).list(); } } EmployeeService.java: public class EmployeeService { private EmployeeDao employeeDao; public EmployeeDao getEmployeeDao() { return employeeDao; } public void setEmployeeDao(EmployeeDao employeeDao) { this.employeeDao = employeeDao; } public List<Employee> getAll(){ return employeeDao.getAll(); } } 测试类SSHTest.java: public class SSHTest { private ApplicationContext ctx = null; private EmployeeService employeeService; { ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); employeeService = (EmployeeService) ctx.getBean("employeeService"); } @Test public void testEmployeeService() { System.out.println(employeeService.getAll()); } } 异常信息如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeDao' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.hibernate.internal.SessionFactoryImpl' to required type 'org.hibernate.Session' for property 'sessionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.hibernate.internal.SessionFactoryImpl] to required type [org.hibernate.Session] for property 'sessionFactory': no matching editors or conversion strategy found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 应该是applicationContext.xml中 配置的 <property name="sessionFactory" ref="sessionFactory"></property> 这一步对应的sessionFactory出错了。网上的例子这样是可以的。然后我把在xml配置bean改成用自动注入注解的方式配置结果就可以,请问这是为什么啊?
SSH整合问题 定义两个action后无法实现注入
我用SSH做了个java web项目,hibernate我是用注解的方式,spring我用xml来配置,首先我定义了一个user Model,以及它对应的userDao,userDaoImpl,userService,userServiceImpl,发现可以正确运行,然后我定义了和user完全一样的people Model,代码如下 people: @Entity public class people { private int id; private String username; private String password; 省略set get方法 } peopleDaoImple: public class peopleImpl implements peopleDao { private HibernateTemplate hibernateTemplate; public HibernateTemplate getHibernateTemplate() { return hibernateTemplate; } public void setHibernateTemplate(HibernateTemplate hibernateTemplate) { this.hibernateTemplate = hibernateTemplate; } public boolean save(people u) { hibernateTemplate.save(u); return true; } } peopleImpl: public class peopleImpl implements peopleService { private peopleDao peopledao; public peopleDao getPeopledao() { return peopledao; } public void setPeopledao(peopleDao peopledao) { this.peopledao = peopledao; } public boolean save(people u) { peopledao.save(u); return true; } } 对应的applicationContext的配置如下: <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" > <property name="dataSource" ref="dataSource"></property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.SQLServerDialect </prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="annotatedClasses"> <list> <value>com.model.User</value> <value>com.model.people</value> </list> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" <property name="sessionFactory" ref="sessionFactory"></property> </bean> peopleDaoImpl的配置如下: <bean id="peopledao" class="com.Dao.Impl.peopleImpl" > <property name="hibernateTemplate" ref="hibernateTemplate"></property> </bean> peopleImpl配置如下: <bean id="peopleService" class="com.ServiceDao.Impl.peopleImpl" > <property name="peopledao" ref="peopledao"></property> </bean> 我觉得奇怪的是 我单单配置一个user时程序没问题,而多加了一个people以后则没办法用spring来为people注入,运行时tomcat服务器没有问题,但浏览器上出现错误500 然后报 java.lang.NullPointerException com.ServiceDao.Impl.peopleImpl.save(peopleImpl.java:21) com.Actions.peopleAction.Register(peopleAction.java:44) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:76)
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、PDF搜索网站推荐 对于大部
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入  假设现有4个人
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
写在前面: 我是 扬帆向海,这个昵称来源于我的名字以及女朋友的名字。我热爱技术、热爱开源、热爱编程。技术是开源的、知识是共享的。 这博客是对自己学习的一点点总结及记录,如果您对 Java、算法 感兴趣,可以关注我的动态,我们一起学习。 用知识改变命运,让我们的家人过上更好的生活。 目录一、杨辉三角的介绍二、杨辉三角的算法思想三、代码实现1.第一种写法2.第二种写法 一、杨辉三角的介绍 百度
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
SQL-小白最佳入门sql查询一
一 说明 如果是初学者,建议去网上寻找安装Mysql的文章安装,以及使用navicat连接数据库,以后的示例基本是使用mysql数据库管理系统; 二 准备前提 需要建立一张学生表,列分别是id,名称,年龄,学生信息;本示例中文章篇幅原因SQL注释略; 建表语句: CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // dosho
【图解经典算法题】如何用一行代码解决约瑟夫环问题
约瑟夫环问题算是很经典的题了,估计大家都听说过,然后我就在一次笔试中遇到了,下面我就用 3 种方法来详细讲解一下这道题,最后一种方法学了之后保证让你可以让你装逼。 问题描述:编号为 1-N 的 N 个士兵围坐在一起形成一个圆圈,从编号为 1 的士兵开始依次报数(1,2,3…这样依次报),数到 m 的 士兵会被杀死出列,之后的士兵再从 1 开始报数。直到最后剩下一士兵,求这个士兵的编号。 1、方
致 Python 初学者
文章目录1. 前言2. 明确学习目标,不急于求成,不好高骛远3. 在开始学习 Python 之前,你需要做一些准备2.1 Python 的各种发行版2.2 安装 Python2.3 选择一款趁手的开发工具3. 习惯使用IDLE,这是学习python最好的方式4. 严格遵从编码规范5. 代码的运行、调试5. 模块管理5.1 同时安装了py2/py35.2 使用Anaconda,或者通过IDE来安装模
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,
程序员:我终于知道post和get的区别
IT界知名的程序员曾说:对于那些月薪三万以下,自称IT工程师的码农们,其实我们从来没有把他们归为我们IT工程师的队伍。他们虽然总是以IT工程师自居,但只是他们一厢情愿罢了。 此话一出,不知激起了多少(码农)程序员的愤怒,却又无可奈何,于是码农问程序员。 码农:你知道get和post请求到底有什么区别? 程序员:你看这篇就知道了。 码农:你月薪三万了? 程序员:嗯。 码农:你是怎么做到的? 程序员:
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
      11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI 算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC
【技巧总结】位运算装逼指南
位算法的效率有多快我就不说,不信你可以去用 10 亿个数据模拟一下,今天给大家讲一讲位运算的一些经典例子。不过,最重要的不是看懂了这些例子就好,而是要在以后多去运用位运算这些技巧,当然,采用位运算,也是可以装逼的,不信,你往下看。我会从最简单的讲起,一道比一道难度递增,不过居然是讲技巧,那么也不会太难,相信你分分钟看懂。 判断奇偶数 判断一个数是基于还是偶数,相信很多人都做过,一般的做法的代码如下
日均350000亿接入量,腾讯TubeMQ性能超过Kafka
整理 | 夕颜出品 | AI科技大本营(ID:rgznai100) 【导读】近日,腾讯开源动作不断,相继开源了分布式消息中间件TubeMQ,基于最主流的 OpenJDK8开发的
8年经验面试官详解 Java 面试秘诀
    作者 | 胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。   Java程序员准备和投递简历的实
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车? 某胡同口的煎饼摊一年能卖出多少个煎饼? 深圳有多少个产品经理? 一辆公交车里能装下多少个乒乓球? 一
相关热词 c# 图片上传 c# gdi 占用内存 c#中遍历字典 c#控制台模拟dos c# 斜率 最小二乘法 c#进程延迟 c# mysql完整项目 c# grid 总行数 c# web浏览器插件 c# xml 生成xsd
立即提问