小编Tim*_*ake的帖子

如何防止JAXB在编组期间编写未使用的命名空间

有没有人能够在使用JAXB的对象编组期间删除未使用的命名空间?以下是所请求功能的链接:https://github.com/javaee/jaxb-v2/issues/103(见说明)

是否有为此配置JAXB的属性?这是在MOXy中修复的吗?

我目前正在遍历需要编组的对象并提取所有需要绑定的类Class[] classesToBeBound.然后我创建一个新的JAXBContext.newInstance(classesToBeBound)

现在未使用的命名空间不包含在XML中.

我知道即使使用未使用的命名空间,xml验证也是有效的,但对我来说这是框架应该处理的东西.

以下链接https://blogs.oracle.com/enterprisetechtips/entry/customizing_jaxb提到各种修复(见文中间部分),但是当试图在这些链接中找到解决方案时,链接被破坏或者没有人真正解决它.

欢迎任何评论.

(编辑)纯文字:

GIVEN

a new instance of JAXBContext and add 2 classes with each a separate namespace. 
Run Code Online (Sandbox Code Playgroud)

什么时候

marshalling a class that has these 2 classes as a property but only 1 of them is not null 
Run Code Online (Sandbox Code Playgroud)

然后

I expect only the namespace of the property that is not null to be visible in the XML. 
Run Code Online (Sandbox Code Playgroud)

但是ACTUAL是

that both namespaces are in the xml. …
Run Code Online (Sandbox Code Playgroud)

java xml namespaces jaxb marshalling

20
推荐指数
1
解决办法
3416
查看次数

在@PostConstruct期间使用@Cacheable的Spring缓存不起作用

与spring框架中的提交有关https://github.com/spring-projects/spring-framework/commit/5aefcc802ef05abc51bbfbeb4a78b3032ff9eee3

初始化设置为从afterPropertiesSet()afterSingletonsInstantiated()的后续阶段

简而言之:这可以防止在@PostConstruct用例中使用缓存时缓存工作.

更长的版本:这可以防止您使用的用例

  1. 在methodB上使用@Cacheable创建serviceB

  2. 使用@PostConstruct调用serviceB.methodB创建serviceA

    @Component 
    public class ServiceA{
    
    @Autowired
    private ServiceB serviceB;
    
    @PostConstruct
    public void init() {
        List<String> list = serviceB.loadSomething();
    }
    
    Run Code Online (Sandbox Code Playgroud)

这导致org.springframework.cache.interceptor.CacheAspectSupport现在不进行初始化,因此不会缓存结果.

protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) {
   // check whether aspect is enabled
   // to cope with cases where the AJ is pulled in automatically
   if (this.initialized) {
//>>>>>>>>>>>> NOT Being called
      Class<?> targetClass = getTargetClass(target);
      Collection<CacheOperation> operations = getCacheOperationSource().getCacheOperations(method, targetClass);
      if (!CollectionUtils.isEmpty(operations)) { …
Run Code Online (Sandbox Code Playgroud)

java postconstruct spring-cache

6
推荐指数
2
解决办法
3247
查看次数

标签 统计

java ×2

jaxb ×1

marshalling ×1

namespaces ×1

postconstruct ×1

spring-cache ×1

xml ×1