"/>
首页 \ 问答 \ Tomcat使用Spring和Axis2重新启动后,注入的bean为null(Injected beans are null after Tomcat restart with Spring and Axis2)

Tomcat使用Spring和Axis2重新启动后,注入的bean为null(Injected beans are null after Tomcat restart with Spring and Axis2)

我有这些豆子:

<bean id="Child" class="test.Child"></bean>

<bean id="Parent" class="test.Parent">
    <property name="child" ref="Child" />
</bean>

我在Tomcat上使用Axis2,Spring和Hibernate。 Axis服务位于Parent bean中。 它在services.xml中映射为SpringBeanName,包括正确的ServiceClass。 我将日志放在Parent bean中的Child bean变量的get和set方法中:

private Child child;
public void setChild(Child child) {
   this.child = child;
   System.out.println(child);
}
public Child getChild() {
   System.out.println(child);
   return child;
}

我有一个在启动时调用的Spring初始化服务,用于在实现ServiceLifeCycle的服务中的startUp方法中加载Spring。

    ClassLoader classLoader = service.getClassLoader();
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            new String[] { "classpath:spring/applicationContext.xml" }, false);
    applicationContext.setClassLoader(classLoader);
    applicationContext.refresh();

这是一个简单的示例项目,因为逻辑在实际中非常复杂。 无论如何,结果是:

  • 在Axis2 war发布服务中部署AAR,一切都加载完美,set方法实际上是用非null对象调用的。
  • 每次调用服务时,都会成功读取子项。

问题是当Tomcat重新启动时。 在起始日志中,使用非null对象调用set方法。 但是当调用服务时 - Null Pointer Exception,child为null。 重新部署AAR会使一切恢复正常。 但是在重新启动之后 - 孩子再次为空。

发生什么事? 我们将不胜感激。

  • 注意:我不会使用new创建子项。 bean的所有范围都是默认的。 我尝试使用原型范围但没有成功。 会话和请求范围引发了一个例外,即这些范围无法识别:

    没有范围注册范围'......'

  • 注意2:取消注释conf文件夹中context.xml中的标记没有改变任何内容。 更改后我重新启动了Tomcat。


I have these beans:

<bean id="Child" class="test.Child"></bean>

<bean id="Parent" class="test.Parent">
    <property name="child" ref="Child" />
</bean>

I use Axis2, Spring with Hibernate on Tomcat. The Axis services are located in the Parent bean. It is mapped as SpringBeanName in the services.xml, including correct ServiceClass. I placed logs in the get and set methods for the Child beans variables inside the Parent bean:

private Child child;
public void setChild(Child child) {
   this.child = child;
   System.out.println(child);
}
public Child getChild() {
   System.out.println(child);
   return child;
}

I have a Spring initializing service called at startup, to load Spring in the startUp method in a service implementing ServiceLifeCycle.

    ClassLoader classLoader = service.getClassLoader();
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            new String[] { "classpath:spring/applicationContext.xml" }, false);
    applicationContext.setClassLoader(classLoader);
    applicationContext.refresh();

This is a simple example project, since the logic is quite more complex in real. Anyway, the result is:

  • Deploy AAR in Axis2 war distribution's services, everything loads perfect, the set method is actually called with non null object.
  • Every time the service is called, child is successfully read.

The problem is when Tomcat get restarted. In the starting logs, the set method is called with non null object. But when the service is called - Null Pointer Exception, child is null. Redeploying the AAR makes everything working again. But after a new restart - the child is null again.

What is happening? Every help will be appreciated.

  • Note: I do not create the child with new. All scopes of the beans are default. I tried with prototype scope with no success. Session and request scopes threw an exception that these scopes are not recognized:

    No Scope registered for scope '...'

  • Note 2: Uncommenting the tag in the context.xml in the conf folder did not changed anything. I restarted Tomcat after the change.


原文:https://stackoverflow.com/questions/21633548
更新时间:2022-10-28 12:10

最满意答案

circle元素的stroke-dasharray属性确定笔划的破折号长度和两个破折号之间stroke-dashoffsetstroke-dashoffset确定笔划破折号开始的偏移量。 在@keyframes规则中,这些属性会被修改,从而最终产生动画效果。 当圆的半径(以及圆周)发生变化时,这些属性(在keyframes设置)也必须与半径成比例地进行修改。

由于设置取决于圆的半径,我认为您不能为两个圆保持相同的动画( @keyframe )设置。 任何时候只有其中一个可以正常工作。

在下面的代码片段中,我完成了使更大的圆圈工作所需的更改。

body,
svg,
circle {
  margin: 0px !important;
  padding: 0px !important;
}
.loader {
  position: relative;
  margin: 0px auto;
  padding: 0px;
  width: 100px;
  height: 100px;
  zoom: 1;
  background-color: grey;
}
.circular {
  -webkit-animation: rotate 3s linear infinite;
  animation: rotate 3s linear infinite;
  height: 100px;
  position: relative;
  width: 100px;
}
.path {
  stroke-dasharray: 1, 440;
  stroke-dashoffset: 0;
  -webkit-animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
  animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
  stroke-linecap: round;
}
@-webkit-keyframes rotate {
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes rotate {
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@-webkit-keyframes dash {
  0% {
    stroke-dasharray: 1, 440;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 89, 440;
    stroke-dashoffset: -77;
  }
  100% {
    stroke-dasharray: 89, 440;
    stroke-dashoffset: -272;
  }
}
@keyframes dash {
  0% {
    stroke-dasharray: 1, 440;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 89, 440;
    stroke-dashoffset: -77;
  }
  100% {
    stroke-dasharray: 89, 440;
    stroke-dashoffset: -272;
  }
}
@-webkit-keyframes color {
  100%, 0% {
    stroke: #d62d20;
  }
  40% {
    stroke: #0057e7;
  }
  66% {
    stroke: #008744;
  }
  80%,
  90% {
    stroke: #ffa700;
  }
}
@keyframes color {
  100%, 0% {
    stroke: #d62d20;
  }
  40% {
    stroke: #0057e7;
  }
  66% {
    stroke: #008744;
  }
  80%,
  90% {
    stroke: #ffa700;
  }
}
<div style="margin-top: 50px;" class="loader">
  <svg class="circular">
    <circle class="path" cx="50" cy="50" r="44" fill="none" stroke-width="8" stroke-miterlimit="10" />
  </svg>
</div>


或者,如果您希望同时为两个圆设置相同的动画( @keyframe )设置,则可以考虑使用transform: scale来创建更大的圆而不是手动修改圆的半径。 ( 但正如你所看到的,输出与修改半径并不完全相同,因此我不会真的推荐这个 )。

body,
svg,
circle {
  margin: 0px !important;
  padding: 0px !important;
}
.loader {
  position: relative;
  margin: 0px auto;
  padding: 0px;
  width: 100px;
  height: 100px;
  zoom: 1;
  background-color: grey;
}
.circular {
  -webkit-animation: rotate 3s linear infinite;
  animation: rotate 3s linear infinite;
  height: 100px;
  position: relative;
  width: 100px;
}
.path {
  stroke-dasharray: 1, 200;
  stroke-dashoffset: 0;
  -webkit-animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
  animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
  stroke-linecap: round;
}
@-webkit-keyframes rotate {
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes rotate {
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@-webkit-keyframes dash {
  0% {
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -35;
  }
  100% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -124;
  }
}
@keyframes dash {
  0% {
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -35;
  }
  100% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -124;
  }
}
@-webkit-keyframes color {
  100%, 0% {
    stroke: #d62d20;
  }
  40% {
    stroke: #0057e7;
  }
  66% {
    stroke: #008744;
  }
  80%,
  90% {
    stroke: #ffa700;
  }
}
@keyframes color {
  100%, 0% {
    stroke: #d62d20;
  }
  40% {
    stroke: #0057e7;
  }
  66% {
    stroke: #008744;
  }
  80%,
  90% {
    stroke: #ffa700;
  }
}
.loader2 {
  transform: scale(2.2);
}
<div class="loader">
  <svg class="circular">
    <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="8" stroke-miterlimit="10" />
  </svg>
</div>


<div style="margin-top: 100px;" class="loader loader2">
  <svg class="circular">
    <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="8" stroke-miterlimit="10" />
  </svg>
</div>


The stroke-dasharray property of the circle element determine the length of the stroke's dash and the space between two dashes whereas the stroke-dashoffset determines the offset at which the stroke's dash starts. Within the @keyframes rules these properties are getting modified and thus ends up producing the animation effect. When the circle's radius (and thus the circumference) is changed, these properties (set within the keyframes) also have to modified in proportion to the radius.

Since the settings depend on the radius of the circle, I don't think you can keep the same animation (@keyframe) settings for both circles. At any time only one of them can work properly.

In the below snippet I have done the changes that are required to make the bigger circle work.

body,
svg,
circle {
  margin: 0px !important;
  padding: 0px !important;
}
.loader {
  position: relative;
  margin: 0px auto;
  padding: 0px;
  width: 100px;
  height: 100px;
  zoom: 1;
  background-color: grey;
}
.circular {
  -webkit-animation: rotate 3s linear infinite;
  animation: rotate 3s linear infinite;
  height: 100px;
  position: relative;
  width: 100px;
}
.path {
  stroke-dasharray: 1, 440;
  stroke-dashoffset: 0;
  -webkit-animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
  animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
  stroke-linecap: round;
}
@-webkit-keyframes rotate {
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes rotate {
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@-webkit-keyframes dash {
  0% {
    stroke-dasharray: 1, 440;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 89, 440;
    stroke-dashoffset: -77;
  }
  100% {
    stroke-dasharray: 89, 440;
    stroke-dashoffset: -272;
  }
}
@keyframes dash {
  0% {
    stroke-dasharray: 1, 440;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 89, 440;
    stroke-dashoffset: -77;
  }
  100% {
    stroke-dasharray: 89, 440;
    stroke-dashoffset: -272;
  }
}
@-webkit-keyframes color {
  100%, 0% {
    stroke: #d62d20;
  }
  40% {
    stroke: #0057e7;
  }
  66% {
    stroke: #008744;
  }
  80%,
  90% {
    stroke: #ffa700;
  }
}
@keyframes color {
  100%, 0% {
    stroke: #d62d20;
  }
  40% {
    stroke: #0057e7;
  }
  66% {
    stroke: #008744;
  }
  80%,
  90% {
    stroke: #ffa700;
  }
}
<div style="margin-top: 50px;" class="loader">
  <svg class="circular">
    <circle class="path" cx="50" cy="50" r="44" fill="none" stroke-width="8" stroke-miterlimit="10" />
  </svg>
</div>


Alternately, if you wish to make the same animation (@keyframe) settings work for both the circles at the same time, then you could consider using a transform: scale to create the bigger circle instead of manually modifying the radius of the circle. (But as you can see, the output is not exactly same as modifying the radius and hence I wouldn't really recommend this).

body,
svg,
circle {
  margin: 0px !important;
  padding: 0px !important;
}
.loader {
  position: relative;
  margin: 0px auto;
  padding: 0px;
  width: 100px;
  height: 100px;
  zoom: 1;
  background-color: grey;
}
.circular {
  -webkit-animation: rotate 3s linear infinite;
  animation: rotate 3s linear infinite;
  height: 100px;
  position: relative;
  width: 100px;
}
.path {
  stroke-dasharray: 1, 200;
  stroke-dashoffset: 0;
  -webkit-animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
  animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
  stroke-linecap: round;
}
@-webkit-keyframes rotate {
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes rotate {
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@-webkit-keyframes dash {
  0% {
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -35;
  }
  100% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -124;
  }
}
@keyframes dash {
  0% {
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -35;
  }
  100% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -124;
  }
}
@-webkit-keyframes color {
  100%, 0% {
    stroke: #d62d20;
  }
  40% {
    stroke: #0057e7;
  }
  66% {
    stroke: #008744;
  }
  80%,
  90% {
    stroke: #ffa700;
  }
}
@keyframes color {
  100%, 0% {
    stroke: #d62d20;
  }
  40% {
    stroke: #0057e7;
  }
  66% {
    stroke: #008744;
  }
  80%,
  90% {
    stroke: #ffa700;
  }
}
.loader2 {
  transform: scale(2.2);
}
<div class="loader">
  <svg class="circular">
    <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="8" stroke-miterlimit="10" />
  </svg>
</div>


<div style="margin-top: 100px;" class="loader loader2">
  <svg class="circular">
    <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="8" stroke-miterlimit="10" />
  </svg>
</div>

相关问答

更多
  • 您可以直接选择.changeCircle并使用$(this)属性来填充svg 。 试试这段代码: $(".changeCircle").on('click', function() { $(this).css({ fill: "#ff0000" }); });
    vector-effect="non-scaling-stroke首先在SVG 1.2 Tiny中引入。这是SVG的一个子集,用于功率有限的移动设备.SVG 1.2没有标记,所以这个问题不是问题。 vector-effect是SVG 1.2 Tiny中唯一的东西,浏览器最终实现了。 不幸的是,当时显然错过了这个问题,我想没有人会把它作为一个bug报告。 虽然我之前已经看到它询问过SO。 好消息是SVG2规范特别指出它应该被解决 ,但现在对你没有帮助。 vector-effect="non-scaling-s ...
  • 这很简单。 将width和height属性转换为viewBox 。 对于您的目的,viewBox将采用以下形式: "0 0 " 所以在这种情况下,它将成为: "0 0 977 1000" 然后将宽度和高度设置为所需大小图标的适当值。 您通常希望它们保持与原始值相同的比例。
  • 您的SVG标记应如下所示: ...... 所以你需要做的就是重置css属性。 像这样的东西应该工作: $('#SomeID').css({'width':40, 'height' :40}); 如果你不能改变SVG标记的id,那么你可以简单地将它包装在这样的div周围:
    ....
    $('#SomeID').find('svg').css({'w ...
  • 我首先想到的是这可以用相对单位来实现,但是SVG的宽高比变化会让你进入热水。 因此,最好的方法似乎是将SVG viewBox钳制到原始图像尺寸。 这些需要事先知道,因为SVGImageElement无法从图像源本身提取它们。 要付出的代价是每次调整窗口大小时都必须调整覆盖圈的大小。 此示例与拖动功能无关。 //an event counter var counter = 0; //image metadata var pData = { url: "https://m.bmw.de/content ...
  • 我可以为您提供两个想法: 1) 也许 SVG导入会考虑原始大小并为您进行缩放。 但是,当在Illustrator中编辑时,你可能会有一个更大的文档,这会混淆svgImport? 2)否则,您可以将纸张作为一组导入。 并缩放集合。 var set = paper.set(); paper.importSVG(svgdata, set); set.scale( 2, 2, centerx, centery ); (我不确定没有一个例子可以玩,中心和中心应该是什么)。 [编辑(批准后)]似乎拉斐尔让你得到一个集 ...
  • 对于给定的半径r ,圆的周长是2πr 。 由于四舍五入,此小提琴中的值略有偏差,但您可以通过设置半径和周长的新值来验证关系是否成立。 小提琴中有三个位置使用圆周。 进入JavaScript之后: var initialOffset = '440'; CSS中两次: .circle_animation { stroke-dasharray: 440; /* this value is the pixel circumference of the circle */ stroke-dashoffset ...
  • circle元素的stroke-dasharray属性确定笔划的破折号长度和两个破折号之间stroke-dashoffset而stroke-dashoffset确定笔划破折号开始的偏移量。 在@keyframes规则中,这些属性会被修改,从而最终产生动画效果。 当圆的半径(以及圆周)发生变化时,这些属性(在keyframes设置)也必须与半径成比例地进行修改。 由于设置取决于圆的半径,我认为您不能为两个圆保持相同的动画( @keyframe )设置。 任何时候只有其中一个可以正常工作。 在下面的代码片段中, ...
  • 您的代码有一些问题。 一个是createAttributeNode()调用。 另一个是document.content引用。 此外还有奇怪的颜色值“centreColour”。 我把一个工作小提琴放在一起。 希望它可以帮助您在代码中使用。 在这里演示 There are a few things wrong with your code. One is the createAttributeNode() calls. Another is the document.content reference. Pl ...
  • 这是一个小提琴的例子 。 注意:我使用r = 57 ,因为周长是358.1 ,接近360 degrees 。 对于不同的r值,您需要计算stroke-dasharray 非常感谢@Robert Longson,@ErikDahlström和@Phrogz多年来的SO解决方案。 这个小提琴只是他们的一个调整。 (function() { // math trick 2*pi*57 = 358, must be less than 360 degree var circle = document. ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)