我正在编写一个Spring集成应用程序,它应该包含多个文件(可能多达100个).我使用OSDelegatingFileTailingMessageProducer作为消息源,这是涉及多个过滤器和通道的管道的开始.
Tailing一个文件可以正常使用这个管道和一个用于通道和转换器的XML配置文件,但拖尾许多这些文件意味着这个XML配置的倍增,这在我看来并不是很好的编程实践.
我想我将不得不通过编程构建Spring应用程序上下文在Java中构建这些管道.还有其他选择吗?
编辑:
可能需要使用BeanFactoryPostProcessor:https://stackoverflow.com/a/15773000/2069922?
我试图在我的Spring应用程序上下文中添加一个简单的String,然后将其自动装配到应用程序上下文中的另一个现有bean(A).我知道这不是通常的方法,但我需要以编程方式添加许多bean,否则会使我的xml配置变得庞大.
public class MyPostProcessor implements BeanFactoryPostProcessor, Ordered {
@Override
public int getOrder() {
return 0;
}
@Override
public void postProcessBeanFactory(
ConfigurableListableBeanFactory beanFactory) throws BeansException {
beanFactory.registerSingleton("myString", "this is the String");
A a = beanFactory.getBean(A.class);
beanFactory.autowireBean(a);
}
}
public class A {
@Autowired
public transient String message;
}
Run Code Online (Sandbox Code Playgroud)
运行此操作时,messageA实例的属性为null.我错过了什么?
编辑:这是我的应用程序上下文:
@Configuration
class TestConfig {
@Bean
public A a() {
return new A();
}
@Bean
public MyPostProcessor postProcessor() {
return new MyPostProcessor();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的考验:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = TestConfig.class)
public …Run Code Online (Sandbox Code Playgroud) 我正在使用Apache AVRO评估我的Jersey REST服务.我正在使用带有Jersey REST的Springboot.
目前我接受JSON作为输入,使用Jackson对象映射器转换为Java Pojos.
我看过不同的地方,但我找不到任何使用带有泽西终点的Apache AVRO的例子.
我找到了这个包含Apache AVRO插件的Github存储库(https://github.com/FasterXML/jackson-dataformats-binary/).
我仍然找不到任何好的例子,如何整合它.有人用过泽西岛的Apache AVRO吗?如果是,是否有任何我可以使用的例子?
我试图用外行的术语来理解信任库和密钥库之间的区别。它们与java中的cacerts有什么关系?我经历了很多线程,但仍然无法理解何时使用密钥库以及何时使用信任库。
当我尝试通过 https 对 Web 服务进行 API 调用时,我不断收到 SSL 证书问题。HTTPS 服务使用的是自签名证书,我将该证书导入到我的 cacert 中,但问题仍然存在。我必须在哪里导入此服务器证书?如果导入解决了问题,我在部署应用程序时是否需要在其他环境中导入证书?
我们的应用程序使用一个 JKS 文件,它需要什么?当我查看 JKS 文件时,我看到其中有 2 个证书。我们为什么用它?
对于 truststore,我看到人们说要相信我们自己。我们凭什么相信自己?信任库是否使用任何证书?什么时候应该使用密钥库而不是信任库?
任何帮助理解这一点对我来说真的很有帮助。
我试图在spark上运行一个例子时遇到错误.任何人都可以让我知道我需要对我的pom.xml进行哪些更改才能运行带有spark的程序.
出于测试目的,我将 tcp 消息发送到本地服务器,如下所示:
echo -e "some message" | netcat localhost 1234
Run Code Online (Sandbox Code Playgroud)
使用brew install netcat.
这工作正常,除了这会阻塞很长时间(大约一分钟)。我尝试使用选项“-w 1”来指定超时,但这不会改变任何内容。
另一端监听的进程是spring-xd tcp源。
有没有其他方法可以发送不阻塞的 tcp 消息?
最新版本的IBM Message Bus是否支持Kafka Streams(此处描述:http://www.confluent.io/blog/introducing-kafka-streams-stream-processing-made-simple/).有关如何执行此操作的任何示例/示例?如果是,可以用node.js完成吗?
我想做的是
将数据从源数据库(Cloudant)流式传输到Kafka流(Bluemix中存在连接器服务 - BETA服务)
使用Kafka Streams汇总数据(摘要,计数等)
Web Dashboard应用程序 - 前端(Node.JS,D3.JS)实时使用流和更新仪表板.
谢谢
我对Spring Security的配置的理解http.anyRequest().authenticated()是,任何请求都必须经过身份验证,否则我的Spring应用程序将返回401响应。
不幸的是,我的spring应用程序没有这种行为,但是允许未经身份验证的请求通过。
这是我的春季安全配置:
@Configuration
@Order(1)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationTokenFilter authenticationTokenFilter;
@Autowired
private TokenAuthenticationProvider tokenAuthenticationProvider;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.addFilterBefore(authenticationTokenFilter, BasicAuthenticationFilter.class)
.antMatcher("/*")
.authenticationProvider(tokenAuthenticationProvider)
.authorizeRequests()
.anyRequest().authenticated();
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/index.html")
.antMatchers("/error")
.antMatchers("/swagger-ui.html")
.antMatchers("/swagger-resources");
}
}
Run Code Online (Sandbox Code Playgroud)
AuthenticationTokenFilter从请求中获取JWT令牌,检查其有效性,从中创建Authentication,然后在SecurityContextHolder中设置身份验证。如果未提供令牌,则SecurityContextHolder.getContext()。getAuthentication()保持为空。
我的控制器如下所示:
@RestController
@RequestMapping("/reports")
@Slf4j
public class ReportController {
@RequestMapping()
@ResponseBody
public List<String> getIds() {
log.info(SecurityContextHolder.getContext().getAuthentication());
return Collections.emptyList();
}
}
Run Code Online (Sandbox Code Playgroud)
当对没有令牌的端点运行curl请求时,我只是得到一个有效的响应:
-> curl 'localhost:8080/reports/'
[]
Run Code Online (Sandbox Code Playgroud)
调试时,我看到的SecurityContextHolder.getContext().getAuthentication() …
我正在尝试在本地minkube群集上运行自定义marklogic映像。Marklogic公开了多个不同的端口用于管理(8001)和查询(8000)。有没有办法在kubernetes上暴露容器的多个端口?
这是我尝试的:
# try to run container with multiple ports exposed.
kubectl run ml3 --image=marklogic-initial-install:9.0-3.1 --port=8001 --port 8002
# create service to expose the container
kubectl expose deployment ml3 --type=LoadBalancer
# use qinikube to open the exposed ports
minikube service ml3
Run Code Online (Sandbox Code Playgroud)
这有可能吗?
kubernetes文档中的这一部分建议确实有可能:
https://kubernetes.io/docs/concepts/services-networking/service/#multi-port-services
但它仅讨论如何配置服务以公开多个端口,而没有说明如何为容器实现此目的-这应该是前提条件。
谢谢!
我有以下JPA实体:
@EntityListeners(AuditingEntityListener.class)
@Entity
public class EntityWithAuditingDates {
@Id
@GeneratedValue
private Long id;
@Temporal(TemporalType.TIMESTAMP)
@CreatedDate
private Date createdDate;
@Temporal(TemporalType.TIMESTAMP)
@LastModifiedDate
private Date lastModified;
private String property;
// getters and setters omitted.
}
Run Code Online (Sandbox Code Playgroud)
以下CrudRepository:
@Service
public interface EntityWithAuditingDatesRepository extends CrudRepository<EntityWithAuditingDates, Long> {
}
Run Code Online (Sandbox Code Playgroud)
并进行以下测试:
@SpringApplicationConfiguration(classes = FooApp.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class AuditingEntityListenerTest {
@Autowired
private EntityWithAuditingDatesRepository entityWithAuditingDatesRepository;
@Test
public void test() {
EntityWithAuditingDates entityWithAuditingDates = new EntityWithAuditingDates();
entityWithAuditingDates.setProperty("foo");
assertNull(entityWithAuditingDates.getCreatedDate());
assertNull(entityWithAuditingDates.getLastModified());
entityWithAuditingDatesRepository.save(entityWithAuditingDates);
assertNotNull(entityWithAuditingDates.getCreatedDate());
assertNotNull(entityWithAuditingDates.getLastModified());
assertEquals(entityWithAuditingDates.getLastModified(), entityWithAuditingDates.getCreatedDate());
entityWithAuditingDates.setProperty("foooo");
entityWithAuditingDatesRepository.save(entityWithAuditingDates);
assertNotEquals(entityWithAuditingDates.getCreatedDate(), entityWithAuditingDates.getLastModified());
}
}
Run Code Online (Sandbox Code Playgroud)
最后一个条件失败了.更新实体后,不应该是createdDate和lastModifiedDate不同?
谢谢!
java ×5
spring ×4
apache-kafka ×1
apache-spark ×1
autowired ×1
avro ×1
command-line ×1
d3.js ×1
docker ×1
hibernate ×1
ibm-cloud ×1
jax-rs ×1
jpa ×1
jwt ×1
keystore ×1
kubernetes ×1
marklogic ×1
port ×1
rest ×1
scala ×1
sockets ×1
spring-xd ×1
stream ×1
tcp ×1
truststore ×1