我想知道,以下两者之间的主要区别是什么:
我知道@SessionScoped和@Stateful允许为每个客户端创建一个新实例.我也知道,对于@ApplicationScoped和@Singleton/@Stateless,它们在客户端之间共享.
但是,我什么时候应该考虑选择一个EJB或另一个更好?
我正在寻找关于Java EE应用程序的DataSource配置的标准,但我在Internet上找到的所有内容都是特定于容器的(例如:带有Tomcat的context.xml).
我发现这个关于<data-source>标签的非常罕见的主题.看到里面的链接,这很有趣.我在Sun/Oracle文档中找不到更多信息.
所以我有几个问题:
<data-source>标签是否适用于所有Web服务器?(Tomcat,JBoss)
多个资源:我们可以<data-source>
在web.xml中有多个标记吗?
当我们使用标签时,我们是否必须<resource-ref>在web.xml中使用标签(用于@Resource注释)<data-source>,还是不必要?
当我们使用"InitialContext"或"@Resource"调用DataSource时,每个调用的实例是否相同?如果是,它更像是EJB Session Bean @Stateless(可能是同一个实例),还是更像EJB Session Bean @Singleton(必须是同一个实例)?
我知道<data-source>标签出现在Java EE 6标准中,但我在哪里可以找到更多有关它的信息?哪个JSR?
谢谢
以下是Disqus的"通用代码"的一部分:
var disqus_config = function () {
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
Run Code Online (Sandbox Code Playgroud)
我不知道的是Disqus如何处理这个函数,因为page是undefined,所以我们无法访问identifier或url.我测试了几个例子:
disqus_config();
console.log(disqus_config.page);
var a = new disqus_config();
Run Code Online (Sandbox Code Playgroud)
但我仍然不明白Disqus如何处理这个undefined元素.
我试图嘲弄RestTemplate用MockRestServiceServer。在调试测试时,响应实体具有良好的状态和内容类型(使用多种状态和内容类型进行测试以检查差异),但是主体始终为 null。
final String uri = "/uri";
final String notNullJsonString = "{}";
// restTemplate is autowired
final MockRestServiceServer mockRestServiceServer = MockRestServiceServer.createServer(restTemplate);
mockRestServiceServer.expect(
MockRestRequestMatchers.requestTo(new URI(uri))
).andRespond(
MockRestResponseCreators.withStatus(HttpStatus.ACCEPTED)
.contentType(MediaType.APPLICATION_JSON)
.body(notNullJsonString)
);
Run Code Online (Sandbox Code Playgroud)
最好的祝福,
我已经使用 Nginx 启动了一个简单的 Docker 容器,我想使用这个 Docker Nginx 作为我的主机上的应用程序(HTTP Tomcat)的反向代理。但我的proxy_pass仅适用于意外的 IP 值。
预期行为:当我docker inspect在容器上使用时,我的网关是172.29.0.1,我的proxy_pass应该使用172.29.0.1。
当前:我必须使用172.18.0.1myproxy_pass才能使其工作,并且我不明白为什么这个随机值有效。如果我不使用172.18.0.1,则会出现 502 HTTP 错误,并且我的 docker 日志显示“上游连接被拒绝”。
我的Dockerfile(仅包含 1 行):
FROM nginx
我的docker-compose(我使用它docker-compse up --build来启动我的容器):
version: '3'
services:
nginx-web:
image: nginx-web
container_name: nginx-web-container
build: .
ports:
- "80:80"
volumes:
- ./volume-sources/nginx-conf-files:/etc/nginx/conf.d/
Run Code Online (Sandbox Code Playgroud)
我的nginx 文件(我的nginx-web值是网关 …
reverse-proxy nginx docker docker-compose nginx-reverse-proxy
我想知道什么是具有单线程执行程序的RESTful Web服务的最佳体系结构.
我的目标 :
instanciated对象的生命周期非常重要(必须只有一个线程队列).我知道RESTful Web服务生命周期是"每个请求"(类似于我认为的@RequestScoped),所以我看到两个选项:
选项1 :
public class RestService {
protected final static Executor executor;
protected final static Implementation1 impl1;
protected final static Implementation2 impl2;
static {
executor = Executors.newSingleThreadExecutor();
impl1 = new Implementation1();
impl2 = new Implementation2();
}
}
@Path("/servicename")
public class MyService extends RestService {
@POST
@Path("/compute")
public void compute(){
executor.execute(new Runnable(){
public void run(){
impl1.compute();
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
选项2:
@Singleton
public class RestService {
private Executor executor; …Run Code Online (Sandbox Code Playgroud) java ×4
datasource ×1
disqus ×1
docker ×1
ejb ×1
executor ×1
function ×1
javascript ×1
lifecycle ×1
nginx ×1
null ×1
resources ×1
rest ×1
resttemplate ×1
singleton ×1
spring ×1
standards ×1
stateful ×1
stateless ×1
undefined ×1
unit-testing ×1
web-services ×1
web.xml ×1