- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道有很多关于tomcat embedded中JNDI Resources的问题,但是我尝试了所有我找到的解决方案都没有成功。
我有一个为我的客户公开 Rest API 的应用程序。在这个应用程序中,我们有一个使用 JMS 和 Amazon SQS 的异步解决方案。该应用程序使用第三方库,使用 JNDI 获取 sql.Datasource,因此,我需要使用 JNDI 数据源。
问题是,当应用程序在 Rest Controller 的同一线程中调用此库时,JNDI 查找工作,并获取数据源。
当我的@JmsListener 调用这个库时,我得到一个 NamingNotFoungException。
我在代码的两点中使用了 context.list("java") 并确认在 JmsListener 内部没有 JNDI 上下文。
我的tomcat工厂类: 配置公共(public)类 CustomTomcatEmbeddedServletContainerFactory {
@Value("${spring.log.datasource.jndiName}")
private String logJndiName;
@Value("${spring.log.datasource.password}")
private String logPassword;
@Value("${spring.log.datasource.url}")
private String logUrl;
@Value("${spring.log.datasource.username}")
private String logUsername;
@Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
return new TomcatEmbeddedServletContainerFactory() {
@Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
tomcat.enableNaming();
return super.getTomcatEmbeddedServletContainer(tomcat);
}
@Override
protected void postProcessContext(Context context) {
// LogDS
context.getNamingResources()
.addResource(
getContextResource(logJndiName, logUrl, logUsername, logPassword)
);
ContextResourceLink contextResourceLink = new
ContextResourceLink();
contextResourceLink.setGlobal(logJndiName);
contextResourceLink.setName(logJndiName);
contextResourceLink.setType("javax.sql.DataSource");
context.getNamingResources().addResourceLink(contextResourceLink);
}
private ContextResource getContextResource(
final String name
, final String url
, final String username
, final String password
) {
ContextResource resource = new ContextResource();
resource.setName(name);
resource.setType(DataSource.class.getName());
resource.setProperty("factory", "com.zaxxer.hikari.HikariJNDIFactory");
resource.setProperty("jdbcUrl", url);
resource.setProperty("dataSource.user", username);
resource.setProperty("dataSource.password", AESCrypto.decrypt(password));
resource.setScope("Sharable");
return resource;
}
};
}
}
知道这个问题吗?
--------更新------------
当我使用下面的代码时,JMSListener 中的上下文解决了,但我的 RestController 不再响应,出现 404 http 状态。
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
tomcat.enableNaming();
TomcatEmbeddedServletContainer container = super.getTomcatEmbeddedServletContainer(tomcat);
for (Container child : container.getTomcat().getHost().findChildren()) {
if (child instanceof Context) {
ClassLoader contextClassLoader = ((Context) child).getLoader().getClassLoader();
Thread.currentThread().setContextClassLoader(contextClassLoader);
break;
}
}
return container;
}
--------更新2--------我的问题已解决。我没有像上面说的那样返回“容器”,而是返回 super.getTomcatEmbeddedServletContainer(tomcat);我的第一次更新中的手动 GlobalContext 运行良好!
最佳答案
我的问题已经解决了。我没有像上面说的那样返回“容器”,而是返回 super.getTomcatEmbeddedServletContainer(tomcat);我的第一次更新中的手动 GlobalContext 运行良好!
关于java - SpringBoot Tomcat内嵌全局JNDI资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46259504/
如果 Rmd 文件中的 R 代码重复使用相同的变量名,则内联 r 表达式似乎返回此变量的最后一个值,而不管内联表达式的位置。除了确保不在文档的不同部分重复使用相同的变量名称之外,是否可以避免这种行为?
我希望多行文本像单个文本 block 一样环绕,例如下面的“Source”和“DEC”字段,而不使用表格。 我想我应该能够使用 inline-block 来让它工作,但我没有成功。 下面是我正在使用的
我不熟悉Inline Anchor styles(link) ,怎样才能让它的作品展现时尚呢? Javascript/JQuery 编码或遗漏了什么? [ http://codepen.io/anon
我正在尝试将嵌入式 ruby 添加到我的 css 样式宽度标签中。 这是目前代码的样子: %"> 不确定我是否只是搞砸了目标变量,或者我的 float 是否已关闭(它正在打印正确的百分比),但
我想制作一个时间轴,但它的结构已损坏。我认为这是因为 display:inline,如果我试图对我的网站这样做,它会破坏它。display: inline-block 也让它变得有趣。 我尝试将 di
这个问题在这里已经有了答案: How to remove the space between inline/inline-block elements? (41 个回答) 关闭 7 年前。 不确定我
我正在尝试使用嵌入式 UIStackViews 来获得如下所示的内容: Label1 ----------------Label2 Label3 -- 所以我在一个水平 UIStackView 中有
是否可以在使用内联 CSS 的同时创建一个盒子模型 hack? 例如: 谢谢! 最佳答案 您也可以在内联样式中使用“前缀”技巧: 只需确保将 IE hack 放在样式属性的末尾即可。然而,我同意尽
有没有人有什么技巧可以在页面上对齐这两个按钮?默认情况下,iframe 版本的 facebook like 按钮显示在 google plus 按钮下方,反之亦然。是否有任何 CSS 技巧可以使它们保
这就是我想要实现的目标。我有一个运行 Suricata 的内联 linux 盒子,能够丢弃数据包。这适用于将所有流量放到 NFQUEUE 0 上然后设置 suricata 监听的标准方法。 我正在编写
我目前正在将元素中的一个页面导出到 Excel,这将不允许链接外部内容,例如外部 CSS。 我想要实现的是一种在我的 View 中包含 CSS 文件但直接从 Visual Studio 自动缩小的 C
在一个两列的框中(column-count: 2),CSS 设置break-inside: avoid 应该避免一些内容从一列中断到其他。这在 Firefox 和 Chrome 中运行良好(使用适当的
几乎完成了我的登录脚本,只需要帮助寻找替代方法: return (mysql_result($query, 0) == 1) ? true : false; 查询: $query = mysqli_q
我正在尝试获取一个具有嵌入式 Tomcat 服务器的 Spring Boot jar,以在运行时加载外部 war 。我正在尝试使用此 post 中显示的技术来执行此操作. Spring Boot应用中
我正在开发 Spring Boot 1.4 应用程序,并且正在为我的 Rest 端点编写集成测试。我正在使用新的测试注释,如下所示: @RunWith(SpringRunner.class) @Spr
我是一名优秀的程序员,十分优秀!