注解就是对xml的代替,采用注解的方式会加快开发速度。但是在实际开发中我们使用注解+xml的方式,因为xml中有些东西,注解无法替代。
注解开发一共分为两步
1.导入jar包
导入struts-convention-plugin.jar
2.配置action
配置照着struts.xml配置就好了
注意
因为我们加载了插件包,struts加载配置文件时就会变成
1.加载default.properties
2. 加载struts-default.xml
3.加载struts-plugin.xml
4.加载struts.xml
5. 加载struts.proprties
6.加载 web.xml
在加载struts-plugin.xml时,里面有一句
这样struts就会扫描你的包了。
<constantname="struts.convention.package.locators"value="action,actions,struts,struts2"/>
这是配置sturts扫描action的,只有在上面那四个包中的action才会被扫描到,如果你的action没写在上述四个包中,你需要改包,或者copy这个配置代码在struts.xml中写上
<constant name="struts.convention.package.locators" value="action,actions,struts,struts2,你的包名"/>
这样struts就会扫描你的包了。
以上是解决找不到action或者运行直接报404错误。