Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One spring bean initialized 2 times when start the jboss, but 1 time when just publish in STS

 
Peter Saw
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using STS and JBoss.
Have a strange problem since this week Monday. It works fine before.
One spring service bean (@Service) will be autowired in another bean.

When start the jboss, find the bean is initialized 2 times.
When just publish, the bean is initialized 1 time only.

I have a transactional method in the bean with @Transactional.
After start the jboss, the transactional works.
But if publish, the transactional does not works.

Anyone has ever experience this? What's the possible reason?

Some questions can be raised.
In which situation or senario the bean could be initialized 2 times automatically?
Why Spring @Transactional dose not work?
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When start the jboss, find the bean is initialized 2 times.
When just publish, the bean is initialized 1 time only.


What do you mean by start and publish? Is start starting the server and publish right clicking the server in STS while it is running in debug and publishing changes to the server? If so what kind of changes are you publishing while its running? You cant make changes to annotations etc without restarting the server.

What do you mean by is initialized 2 times? Are you initializing the same XML twice in your web.xml? Are the beans defined multiple times in different web contexts? Do you have multiple component scanners scanning the same packages? Do you have @Configuration classes being picked up twice? In the end in most cases you will end up with a single spring bean but things like I have listed can cause multiple initializations.

That is about the most help I can give you without seeing more of your actual configuration. Also perhaps your start-up log showing the multiple initialization may help. Some times dropping the logging level down to debug for your Spring stuff can help you better debug whats happening on start-up.

Good Luck


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic