Hi folks,
I just finished the Annotations Tutorial at Struts's cwiki [1] and ran into
a bit of a problem. I was wondering if someone could please shed a light
on. Here's my dev environment:
Windows 8.1 x64
Oracle/Sun JDK 1.7.0_45
Tomcat 7.0.50
Struts 2.3.16
Eclipse Kepler SR-1
The tutorial project works fine when my packages within src/main/java is
different (ie. annotations.*) from my group + artifact (ie.
local.workgroup.tutorial.struts2). If it matches, it errors reporting
unmapped actions:
--------------------------------------------------------------------------------
snippet from pom.xml:
<groupId>local.workgroup.tutorial.struts2</groupId>
<artifactId>annotations</artifactId>
<packaging>war</packaging>
--------------------------------------------------------------------------------
Works with below package:
package annotations.actions;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;
public class HelloAction extends ActionSupport {
//...
}
--------------------------------------------------------------------------------
Errors when package is:
package local.workgroup.tutorial.struts2.actions;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;
public class HelloAction extends ActionSupport {
//...
}
****************************************************************
Here's a brief error:
Struts has detected an unhandled exception:
*Messages*:
There is no Action mapped for namespace [/] and action name [hello]
associated with context path [/annotations].
Looking at the /annotations/config-browser/index.action, there are no
actions listed under default namespace. However, under the /actions
namespace:
Actions in /actions
-
hello<http://localhost:8080/annotations/config-browser/showConfig.action?namespace=%2Factions&actionName=hello>
-
register<http://localhost:8080/annotations/config-browser/showConfig.action?namespace=%2Factions&actionName=register>
-
register-input<http://localhost:8080/annotations/config-browser/showConfig.action?namespace=%2Factions&actionName=register-input>
If I tried /annotations/actions/hello.action, I get this error:
Struts has detected an unhandled exception:
*Messages*:
No result defined for action
local.workgroup.tutorial.struts2.actions.HelloAction and result success
Even though the class is:
package local.workgroup.tutorial.struts2.actions;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;
public class HelloAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(HelloAction.class
.getName());
private String message;
public String execute() throws Exception {
logger.info("In execute method of class Hello");
message = "Hello from Struts 2 with no XML configuration.";
return SUCCESS;
}
public void setMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}
The convention plugin doc also uses similar package naming method [3]. Did
I name the packages wrong or did I just stumble on a bug in 2.3.16? Is
there a small print somewhere that I may missed regarding not able to use
package naming method similar to group ID + artifact ID in pom.xml? If I
use struts.xml for the previous tutorials and not used convention plugin,
the package naming works fine.
Thanks,
Tommy
[1] https://cwiki.apache.org/confluence/display/WW/Struts+2+Annotations
[2] http://localhost:8080/annotations/config-browser/actionNames.action
[3] http://struts.apache.org/release/2.1.x/docs/convention-plugin.html