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
最满意答案
circle
元素的stroke-dasharray
属性确定笔划的破折号长度和两个破折号之间stroke-dashoffset
而stroke-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 thecircle
element determine the length of the stroke's dash and the space between two dashes whereas thestroke-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 thekeyframes
) 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 atransform: 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" }); });