https://github.com/QiSimon/Projects.git
400错误说明找不到资源,可以看看是不是部署的时候有错误。
补充一下,这个报错刚碰到,是struts配置文件中action标签内的class名称和spring配置文件中的bean id不一致
class中应该是 cn.muke.ssh.action.ProductAction
题外话:我的跳转addProduct.jsp页面也报错500,空指针异常???
你看着视频里笔记,自己敲一遍啊
单例肯定是同一个对象 多例肯定就不是,你说的hashcode值都一样是指用什么创建对象的时候?还是不管struts。spring都一样,我测试的hashcode值虽然一样在多例的时候,但肯定不是一个对象;
我要是这个bug,你解决了吗
检查你Productservice在applicationContext.xml是否配置正确
spring框架的核心监听器是不是没配好
可不可发一下你的代码
这个应该是bean的id名字的问题,注意字母大小写
<!--配置action层 -->
<bean id="productaction" class="com.action.ProductAction" scope="prototype">
<property name="productservice" ref="productservice"></property>
</bean>
<!--配置service层 -->
<bean id="productservice" class="com.service.ProductService">
<property name="productdao" ref="productdao"></property>
</bean>
<!--配置dao层 -->
<bean id="productdao" class="com.dao.ProductDao">
</bean>
嗯,我这个问题也没有解决。是不是web.xml无法将struts2和spring配置起来
肯定是没配置好,要么就是bean.xml没有配置实例化,要么就是没有注入,因为没有实体,只能用静态方法
解决了吗,同错误
你的applicationContext.xml中有没有配置ProductAction类
<!-- 配置Action类 -->
<bean id="productAction" class="cn.muke.ssh.action.ProductAction" scope="prototype">
<!-- 手动注入Service -->
<property name="productService" ref="productService"></property>
</bean>
在<action name="product_*" class="productAction" method="{1}">中class属性里应该写入productAction的完整包路径。
我的也是,怎么解决?
Service类中,ProductDao.save(product);ProductDao小写productDao,你这是类名调用了。
先发布项目,在启动
贴上的代码应该没问题,我觉得应该是ProductAction类中的save方法有问题,方法名拼错啦、权限没有public啦之类的问题
手动的话就直接New 自动设值得包不要导入了 set方法也没用了 自己处理必须要set方法 还有一种构造参数注入值方法
你商品价格输入的是数字吗?
可能我觉得xml方式逻辑清晰点,注解可能速度快,但是逻辑不怎么清晰,看个人习惯,一开始我学Struts2也是喜欢用注解,后来接触了xml反而觉得xml更适合我