restygwtを使用してサーバーとクライアントの通信を試みています。したがって、サービス インターフェイス (クライアント) とコントローラー (サーバー) があります。
@Path("/user")
public interface UserAdminRestService extends RestService {
@GET
@Path("/users")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public void getUsers(MethodCallback<List<GWTUser>> methodCallback);
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public void getUser(Integer id, MethodCallback<GWTUser> callback);
}
@Controller
@RequestMapping(value ="/user")
public class AdminSpringController {
@RequestMapping(value = "/users", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody List<GWTUser> getUsers() {
...
}
@RequestMapping( value = "/{id}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody GWTUser getUser(@PathVariable Integer id) throws NotFoundException { ...
}
}
特定のデータを取得するには、MethodCall を作成します。
Defaults.setServiceRoot(GWT.getHostPageBaseURL());
UserAdminRestService userService = GWT.create(UserAdminRestService.class);
((RestServiceProxy)userService).setResource(new Resource("/user"));
userServiceClient.getUsers(new MethodCallback<List<GWTUser>>() {
@Override
public void onFailure(Method method, Throwable exception) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(Method method, List<GWTUser> response) {
view.setUserList(response);
}
});
しかし、アプリケーションをビルドしようとすると、次のエラー メッセージが表示されます。
[INFO] Compiling module my.app.web
[INFO] Computing all possible rebind results for 'my.app.client.UserAdminRestService'
[INFO] Rebinding my.app.client.UserAdminRestService
[INFO] Invoking generator org.fusesource.restygwt.rebind.RestServiceGenerator
[INFO] Generating: my.app.client.UserAdminRestService_Generated_RestServiceProxy_
[INFO] [ERROR] Content argument must be a class.
[INFO] [ERROR] Errors in 'my/app/admin/client/activity/UserListActivity.java'
[INFO] [ERROR] Line 69: Failed to resolve 'my.app.client.UserAdminRestService' via deferred binding
[INFO] [WARN] For the following type(s), generated source was never committed (did you forget to call commit()?)
[INFO] [WARN] my.app.client.UserAdminRestService_Generated_RestServiceProxy_
LINE 69: はUserAdminRestService userService = GWT.create(UserAdminRestService.class);
何が間違っているのかわかりません。アイデアや助けをありがとう:)
編集:
GWT ユーザー
パブリック クラス GWTUser {
/**
* Certain user entity id. Only for representation, can not be
* persisted into the database.
*/
private int id;
/**
* Certain user id.
*/
private String userId;
/**
* user password.
*/
private String password;
/**
* Represents a certain status if user is enabled.
*/
private boolean enabled = true;
/**
* Represents a certain status if user is locked.
*/
private boolean locked = false;
/**
* user e-mail.
*/
private String email;
/**
* full user name.
*/
private String name;
/**
* the version of the real user entity. Only for representation, can not be
* persisted into the database.
*/
private int version;
// Getter and Setter
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isLocked() {
return locked;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((userId == null) ? 0 : userId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
GWTUser other = (GWTUser) obj;
if (userId == null) {
if (other.userId != null)
return false;
} else if (!userId.equals(other.userId))
return false;
return true;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("User [userId=");
builder.append(userId);
builder.append(", name=");
builder.append(name);
builder.append(", email=");
builder.append(email);
builder.append(", password=");
builder.append(password != null ? "****" : "<not set>");
builder.append(", enabled=");
builder.append(enabled);
builder.append(", locked=");
builder.append(locked);
builder.append("]");
return builder.toString();
}
}
編集:
gwt.gwt.xml file containing all the gwt code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module SYSTEM "gwt-module.dtd">
<module>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<inherits name='com.google.gwt.activity.Activity'/>
<inherits name='com.google.gwt.place.Place' />
<inherits name='org.fusesource.restygwt.RestyGWT' />
<!-- Use ClientFactoryImpl by default -->
<replace-with class="my.app.client.factory.ClientFactoryImpl">
<when-type-is class="my.app.client.factory.ClientFactory"/>
</replace-with>
<!--Specify the app entry point class. -->
<entry-point class='my.app.client.AdminEntryPoint'/>
<source path='rest'/>
<source path='client'/>
<source path='consts'/>
</module>
および web.gwt.xml ファイル:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module SYSTEM "gwt-module.dtd">
<module rename-to="web">
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<inherits name='org.fusesource.restygwt.RestyGWT' />
<inherits name='my.app.gwt' />
</module>
UserAdminRestService
インターフェイスと の両方GWTUser
がまだ同じ であるため、2 つのモジュールのために問題があると思います。