I have a Java Web App (Spring) with some classes exposed to JMX. Let's call this project 'A'.
A has a dependency jar called B. B in turn has a dependency C.
Now I would like to expose a Class in C via JMX. So I decorated the class with the following
#ManagedResource(objectName = "A:name=myClassInC")
public class MyClassInC
But this doesn't seem to have any effect and the MyClassInC doesn't show up in the JMX console along with the other classes that are visible from A. The Spring JMX configuration actually resides in the context files of A. So I'm guessing that classes in C should also pick up the same configuration and show up in the JMX console. I'm wondering how I can fix this. Thanks!
Related
I have an application called A packaged as a war.
I have an interface called CustomerLogic packaged in a jar.
Application A has a dependency and includes interface CustomerLogic in its war.
Now I would like to give this application to different customers so they can write their own logic by creating a class, implementing interface CustomerLogic, package it as a(EJB?) jar. And deploy that to the application server, in this case Glassfish.
So in my application code I have:
#Inject
private CustomerLogic customerLogic;//This will hopefully inject any implementation of the interface
But this fails to deploy since there are no implementations of CustomerLogic available yet.
So I create a customer specific jar that contains:
public class VolvoLogic implements CustomerLogic
and deploys this to the glassfish.
But this fails cause the interface can't be found, it resides in application A's war.
Am I thinking about this in the wrong way. What is the best way to do this.
I don't think I want to create an EAR cause I don't want to rebuild the application every time a new customer wants it. I just want to ship the standard untouched application and they can implement their own logic.
I have some personal project where I am trying to share some class instance between webapp and a normal app. My project structure is something like below:
+ NormalApp
+ WebApp
I am starting the application from the NormalApp and I included WebApp using EmbeddedTomcat. Now I have a class named Notifier in WebApp. I want to use the instance of Notifier in NormalApp without losing it's state.
Could someone tell me how can I achieve this scenario?
I have some plan in mind like setting the Tomcat class loader to use Systems class loader. I tried it but couldn't able to achieve it. Is my understanding of this wrong?
Have you tried making your normal app like web components ? so your application will be available when tomcat start. And you can use System properties to pass parameters to the tomcat.
Another option is using Spring boot. Here is a tutorial
https://spring.io/guides/gs/spring-boot/
http://spring.io/guides/tutorials/bookmarks/
I am having some classpath issue. I have a Web Application which is a web service. It uses JaxB and CXF. The web service has a dependecy of another JAR which is a Web Service Client. Now both the client and the service codes are generated by using wsdl2java plugin. The problem looks like this:
Parent WebService WAR
--PackageA
--ClassB
Dependency Jar
--PackageA
--ClassB
So both of them have the same package and the same class name and since these are generated by the plugin, it makes difficult to refactor one of the package so that they would not be identical.
The WebService calls the client and in client code initializes the parent classB from web service instead of the classB from web service client Jar. The only problem in this ClassB is that they have one method which takes differnet parameter, in one class B it takes, Date whereas in another classB it takes XmlGregorianCalendar. So while calling the client i am getting nosuchmethodexception.
Here is what i tried so far without luck:
1: In the Client jar i tried giving the full package and class name to initialize the ClassB
2: In the Client jar i tried wiring the classes using Spring bean and surprisingly it is still wiring the class from the webService instead of the client
3: In the web service ClassB, i tried adding the same method that takes the right parameter. This works partially but result in another exception which is not good.
Looking forward for your help. Thanks!
Solved the issue by passing extra args to wsdl2java plugin while generating classes from the wsdl as per user2880879 suggestion like this:
<extraarg>-p</extraarg>
<extraarg>http://www.example.com=mypackagename</extraarg>
I believe you are creating webservice using top down approach, means write java class first using jaxws annotations and then create wsdl using cxf maven plugin or ant, and use this wsdl to create client ?
If you are following this approach then you can provide binding file when you generate web service client code. click here to know what is binding file and how to write.
In this binding file you can specify package name you want to change for client code.
I am not exposed to Spring as yet. I saw the below code in one of the standalone java projects that I have in my system. Can you please help me understand the below code.I am unable to see spring.xml in the project - is it something that must be there and is missing?
appContext = new ClassPathXmlApplicationContext(new String[] {
"classpath*:/META-INF/spring.xml",
"classpath*:myapplication-application-context.xml"
});
The classpath* syntax means that Spring will search the classpath for all resources called /META-INF/spring.xml and myapplication-application-context.xml, and will amalgamate them into the context. This includes looking through JAR files inside the project, so there may not be any visible within your main project files.
The core functionality of Spring revolves around the ApplicationContext which is the "Central interface to provide configuration for an application. " This interface is implemented by the ClassPathXmlApplicationContext which helps you take the context definitins from your classpath .Hence you specify classpath* .
As #skaffman explains , your application get loaded from the context definitions in the above mentioned files . i.e, all the Spring beans are initialized and Dependency Injection is performed as required .
If you deal with web applications , Spring has got a corresponding web application context loaded by XmlWebApplicationContext
I'm developing a Spring application which shall be used by any kind of other application, no matter if that is a Spring project, a web application or even a simple single-class console application. The application who uses my project will just have to add the JAR file with my application.
So my project has a static factory class that gets and returns a bean from its Spring context which acts as an access object to access all public available functions of my project.
That part is already working.
But I need the developer of the application that uses my JAR to be able to overwrite certain configurations in my project without editing the config files in the JAR itself. At the moment those settings should be overwritable:
- the data source and hibernate bean configuration
- the jasypt (encryption) bean configuration
- the log4j settings
How do I make those settings overwriteable with configs from outside the jar?
Greetings
touchdown
Maybe a good solution would be a configuration that the user could override, for this take a look into:
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-java
Specially to #Configuration and #Bean
Maybe you could have a configuration class implemented and the user can override it. After extending the class and overwrite some methods that provides some beans the user shall inform it to your factory that will do nothing else than
new AnnotationConfigApplicationContext(userConfigurationClass);
If you want to replace the complete configuration, than the easyest way would be to have a parametrized factory that takes an alternative configuration file as its argument.
If you need it a bit more fine grain (lets say up to 10 parts), than you can split your application xml in several smaller once, and use again a configurable factory that allows to exchange the smaller xml files.
So I got a solution that is working for me.
I put an general import for override context-XMLs at the bottom of my main application context:
<import resource="classpath*:project/package/config/override/or-*.xml" />
So all the user has to do is to create the package "project/package/config/override" in his classpath (e.g. resource folder) and place matching XML files in it with new bean definitions.