我以两种方式开发了RESTful Web服务:
使用Glassfish时,使用javax.ws.rs.core.Application了一个扩展而没有定义web.xml文件的类.
没有使用javax.ws.rs.core.Application但包括a web.xml和Jersey实现,使用Tomcat.
有没有一种使用JAX-RS构建RESTful Web服务的首选方法?
以下代码来自JPA规范.我无法理解为什么em.joinTransaction()需要createLineItem(int quantity).
任何人都可以提供合适的解释吗
@Stateful
public class ShoppingCartImpl implements ShoppingCart {
@PersistenceUnit
private EntityManagerFactory emf;
private EntityManager em;
private Order order;
private Product product;
@PostConstruct
public void init() {
em = emf.createEntityManager();
}
public void initOrder(Long id) {
order = em.find(Order.class, id);
}
public void initProduct(String name) {
product = (Product) em
.createQuery("select p from Product p where p.name = :name")
.setParameter("name", name).getSingleResult();
}
public LineItem createLineItem(int quantity) {
em.joinTransaction();
LineItem li = new LineItem(order, …Run Code Online (Sandbox Code Playgroud) 使用 ResourceConfig 比 Application 有什么优势(因为 ResourceConfig 扩展了 Application)。
使用资源配置
@ApplicationPath("/")
public class MyApplication extends ResourceConfig {
public MyApplication() {
super(MultiPartResource.class, MultiPartResource.class, MultiPartFeature.class);
}
}
Run Code Online (Sandbox Code Playgroud)
使用应用程序
public class MyApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<Class<?>>();
// register resources and features
classes.add(MultiPartFeature.class);
classes.add(MultiPartResource.class);
classes.add(LoggingFilter.class);
return classes;
}
}
Run Code Online (Sandbox Code Playgroud)
在多部分表单数据的Jersey 2 注入源后,@ Arul Dhesiaseelan 回答将 MultiPartFeature 添加到两者以在服务器端启用该功能。有人可以解释一下。
为什么不能 void say(List< ? extends Number> list)被覆盖 void say(List< Number> list).
尝试编译时发生名称冲突.
我想构建一个 Maven 项目,它同时具有 java 和 scala 源代码。我已经在 eclipse 中安装了 scala IDE 插件,并在 pom.xml 中添加了“scala-maven-plugin” ,但是 scala 文件中 java 类的导入给出了编译错误。构建此类混合项目的最佳 IDE 是什么?
项目结构是
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.spark</groupId>
<artifactId>spark-examples_2.11</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.7</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!-- This plugin compiles Scala files -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plugin compiles Java files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution> …Run Code Online (Sandbox Code Playgroud) java ×3
rest ×2
web-services ×2
eclipse ×1
jax-rs ×1
jersey ×1
jpa ×1
maven ×1
persistence ×1
scala ×1
transactions ×1