tietang / javamelody

Automatically exported from code.google.com/p/javamelody
0 stars 1 forks source link

Not able to monitor spring business facade #331

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. In the spring MVC 3.X project, Service object is autowired in Controller 
class using @Autowired annotation. Each service class has its own interface.
//code snippet from my controller class
    @Autowired
    private RefDataService refDataService;

2. web.xml is modified to include javamelody config file
//snippet from my web.xml
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:net/bull/javamelody/monitoring-spring.xml
            classpath:/META-INF/spring/root-context.xml
        </param-value>
    </context-param>

    <filter>
        <filter-name>monitoring</filter-name>
        <filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>monitoring</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>net.bull.javamelody.SessionListener</listener-class>
    </listener>

3. In the service interface, I am using 
@net.bull.javamelody.MonitoredWithSpring annotation at the interface level for 
monitoring the service classes (9. Business facades (if Spring)) - Alternative 
to Step 3.
//code snippet from my serviceImpl class
@Service
@net.bull.javamelody.MonitoredWithSpring
public class RefDataServiceImpl implements RefDataService{

4. I have tried putting this annotation at interaface level, class level and 
method level too, but still I am not getting spring related statistics.

What is the expected output? What do you see instead?
I want to see the statistics for Spring, but I don't see anything in that 
section

What version of the product are you using? On what application server, JDK,
operating system?
javamelody1.44.0.jar + jrobin-1.5.9.1.jar + Tomcat 6.0.37 + JDK 1.5 + windows 7

Please provide any additional information below.
- I have also tried the other approach by adding a common interface to all my 
service objects and modified root-context.xml to have below line to make it 
work, but still it doesn't work.

    <!-- Bean definition for java melody -->
    <beans:bean id="facadeMonitoringAdvisor" class="net.bull.javamelody.MonitoringSpringAdvisor">
        <beans:property name="pointcut">
            <beans:bean class="net.bull.javamelody.MonitoredWithInterfacePointcut">
                <beans:property name="interfaceName" value="be.bgc.uti.service.Monitored"/>
            </beans:bean>
        </beans:property>
    </beans:bean>

I even tried by giving the name of the service class itslef to see if it works 
for that service, but still nothing seems to be working.
    <!-- Bean definition for java melody -->
    <beans:bean id="facadeMonitoringAdvisor" class="net.bull.javamelody.MonitoringSpringAdvisor">
        <beans:property name="pointcut">
            <beans:bean class="net.bull.javamelody.MonitoredWithInterfacePointcut">
                <beans:property name="interfaceName" value="be.bgc.uti.service.impl.RefDataServiceImpl"/>
            </beans:bean>
        </beans:property>
    </beans:bean>       
All the other reports are coming fine, but only the Statistics Spring section 
is not filled.

Original issue reported on code.google.com by priyank....@gmail.com on 9 Aug 2013 at 11:52

GoogleCodeExporter commented 9 years ago
Are you able to give a simple zip of project's sources or a simple war of 
webapp to reproduce the issue?

Original comment by evernat@free.fr on 9 Aug 2013 at 12:23

GoogleCodeExporter commented 9 years ago
It won't be possible to share the source code or the war file :(

Original comment by priyank....@gmail.com on 9 Aug 2013 at 12:48

GoogleCodeExporter commented 9 years ago
OK, but can you write a simple hello world project to reproduce the problem and 
to give the zip file of the project?

Original comment by evernat@free.fr on 10 Aug 2013 at 4:27

GoogleCodeExporter commented 9 years ago
As i was not able to attach the file here, I have sent the source code 
replicating this issue in a mail. Kindly confirm once you receive it. Thanks.

Original comment by priyank....@gmail.com on 12 Aug 2013 at 10:56

GoogleCodeExporter commented 9 years ago
PFA the sample code replicating this issue.

Original comment by priyank....@gmail.com on 12 Aug 2013 at 12:22

Attachments:

GoogleCodeExporter commented 9 years ago
Here is the same project's code using maven, and using the same javamelody, 
tomcat and libraries versions than yours code.
The webapp can be started in tomcat with the command "mvn tomcat6:run".

For a test case, I prefer it that way, because it is smaller (7 KB vs 5.5 MB) 
and because I know where the jar files come from.

Original comment by evernat@free.fr on 12 Aug 2013 at 10:21

Attachments:

GoogleCodeExporter commented 9 years ago
Yes i am running the project using maven now. Were you able to replicate the 
issue? I can see that the spring statistics section is not populated in the 
report.

Original comment by priyank....@gmail.com on 13 Aug 2013 at 8:19

GoogleCodeExporter commented 9 years ago
Have you read the Spring's documentation?
http://static.springsource.org/spring-webflow/docs/2.0.x/reference/html/ch12s03.
html

When you use org.springframework.web.servlet.DispatcherServlet, it creates its 
own spring application context, which is not the same as 
org.springframework.web.context.ContextLoaderListener.

So you have to declare the monitoring spring beans in your DispatcherServlet, 
by adding contextConfigLocation in the servlet in web.xml, and you can remove 
the ContextLoaderListener from web.xml.

For example :
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:net/bull/javamelody/monitoring-spring.xml
                /WEB-INF/spring-servlet.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

bad and good web.xml examples are attached.

Original comment by evernat@free.fr on 13 Aug 2013 at 1:00

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by evernat@free.fr on 13 Aug 2013 at 1:01

GoogleCodeExporter commented 9 years ago
evernat:

I can start my application with your good_web.xml example, but every time the 
rest-service gets called, my application throws an exception like this: "No 
WebApplicationContext found: no ContextLoaderListener registered?".

So my question is: are you entirely sure you can live without the 
ContextLoaderListener? And in that case, is there any further steps?

http://stackoverflow.com/questions/8924761/no-webapplicationcontext-found-no-con
textloaderlistener-registered

Original comment by jahes...@gmail.com on 11 Dec 2013 at 3:05