简体   繁体   中英

Created a restful webservice using tomcat server

I created a restful webservice using netbeans created a entity class from the database and restful web services from entity class using jpa but i used tomcat as my server now the post method below wont insert the following json into the database but when i use glassfish as my server it works. Do you think I am missing any dependencies ? How can I emulate the glassfish?

I am trying to insert

{
"acceptedGender":"both",
"price":123123.00,
"type":"apartment"
"vacantNum":13,
"hadID":4
}

I have the following dependencies:
javaee-api-7.0.jar
javax.ejb-api.jar
mysql-connector-java-5.1.42-bin.jar

 @POST
 @Override
 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
 public void create(Students entity) {
    super.create(entity);
 }`

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "hatID")
private Integer hatID;
@Basic(optional = false)
@Column(name = "type")
private String type;
@Basic(optional = false)
@Column(name = "acceptedGender")
private String acceptedGender;
@Basic(optional = false)
@Column(name = "vacantNum")
private int vacantNum;
// @Max(value=?)  @Min(value=?)//if you know range of your decimal fields 
consider using these annotations to enforce field validation
@Basic(optional = false)
@Column(name = "price")
private BigDecimal price;
//    @OneToMany(cascade = CascadeType.ALL, mappedBy = "hatID")
//    private Collection<Reservation> reservationCollection;
@JoinColumn(name = "hadID", referencedColumnName = "hadID")
@ManyToOne(optional = false)
private HaDetails hadID;

public HaTypes(Integer hatID, String type, String acceptedGender, int 
vacantNum, BigDecimal price) {
    this.hatID = hatID;
    this.type = type;
    this.acceptedGender = acceptedGender;
    this.vacantNum = vacantNum;
    this.price = price;`

Or if you dont have a solution to my problem could you recommend any provider aside from aws(dont have the time to study the docker), openshift and jelastic that could deploy a glassfish restful webservice on cloud easily.

Glassfish is an application server, therefore it supports JAX-RS out of the box. Tomcat is just a web container and you cannot deploy a JAX-RS app and have it work without wiring it by yourself (see this: In which container do JAX-RS web services run? ).

If you want to run a Jersey server inside tomcat, you will need to configure it in your application's deployment descriptor. You can see answers on the following posts if you need details:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM