i have a jar named SpringPoc.jar which i have exported using eclipse as a runnable jar
inside the jar i have 2 classes
one is
public class NormalServlet {
public void executeScheduler() {
ApplicationContext context =
new ClassPathXmlApplicationContext("com/serv/Beans.xml");
CallMeth obj = (CallMeth) context.getBean("callMeth");
obj.test();
}}
2nd class is Main App
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("com/serv/Beans.xml");
CallMeth obj = (CallMeth) context.getBean("callMeth");
obj.test();
}}
i have defined a single bean inside Beans.xml
<bean id="callMeth" class="com.poc.CallMeth"/>
then i have created a simple java project in eclipse having a test class
which calls the jar and tries to execute the above class NormalServlet
public class Test {
public static void main(String[] args) {
try {
URL[] classLoaderUrls = new URL[]{new URL("file:\\D:\\MyWorkspace\\Scheduler\\src\\com\\callit\\SpringPoc.jar")};
URLClassLoader urlClassLoader = new URLClassLoader(classLoaderUrls);
Class classToLoad = Class.forName ("com.serv.NormalServlet", true, urlClassLoader);
Method method = classToLoad.getDeclaredMethod ("executeScheduler");
Object instance = classToLoad.newInstance ();
Object result = method.invoke (instance);
} catch (Exception e) {
e.printStackTrace();
}
}
}
when i run test class
i get the below error
Sep 09, 2016 11:48:30 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#1c50507: startup date [Fri Sep 09 11:48:30 IST 2016]; root of context hierarchy
Sep 09, 2016 11:48:30 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [com/serv/Beans.xml]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.callit.Scheduler.callMe(Scheduler.java:40)
at com.callit.Scheduler.main(Scheduler.java:15)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [com/serv/Beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [com/serv/Beans.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.serv.NormalServlet.executeScheduler(NormalServlet.java:17)
... 6 more
Caused by: java.io.FileNotFoundException: class path resource [com/serv/Beans.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
... 19 more
if i run the same jar from cmd
as java -jar SprrinPoc.jar
the MainApp class is called and the Beans.xml loads fine
Question is why doesn't it load when i call Normalservlet externally from test class
Thanks a lot
As long as the dependency jar has file included xxx.xml, it should be available in your host project classpath as well. This will search applicationcontext.xml anywhere in classpath
ApplicationContext context = new ClassPathXmlApplicationContext(
"classpath*:**/applicationContext.xml");
Related
I have a maven application , when I run my application using xml-jetty I am getting the Failed to read candidate component class, nested exception is ArrayStoreException: java.lang.String error for target/classes/com/test/SampleImpl class, I have seen the original SampleImpl.java file, I couldn't find any errors related to that file. I did some research on this error, I found some suggestions related to changing java version 7 to 8 for spring, I changed java version to 8and spring version to 4.x bt still getting same error, then I added some spring dependencies in dependency-management as suggested in other sites but still getting same error.
[main] INFO xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/beans.xml]
[main] INFO xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml]
[main] INFO xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/cxf/cxf-servlet.xml]
[main] ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\Projects\my-server\target\classes\com\my\pack\impl\SampleImpl.class]; nested exception is java.lang.ArrayStoreException: java.lang.String
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:290)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:195)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:801)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:446)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:793)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:296)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1347)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:745)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117)
at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:281)
at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:213)
at org.eclipse.jetty.util.component.ContainerLifeCycle.updateBeans(ContainerLifeCycle.java:763)
at org.eclipse.jetty.server.handler.HandlerCollection.setHandlers(HandlerCollection.java:89)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.setHandlers(ContextHandlerCollection.java:144)
at org.eclipse.jetty.server.handler.HandlerCollection.addHandler(HandlerCollection.java:155)
at org.eclipse.jetty.deploy.bindings.StandardDeployer.processBinding(StandardDeployer.java:41)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:498)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64)
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:605)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391)
at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:560)
at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:235)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117)
at org.eclipse.jetty.server.Server.start(Server.java:355)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
at org.eclipse.jetty.server.Server.doStart(Server.java:324)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1250)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174)
Caused by: java.lang.ArrayStoreException: java.lang.String
at org.springframework.util.ObjectUtils.addObjectToArray(ObjectUtils.java:188)
at org.springframework.core.type.classreading.RecursiveAnnotationArrayVisitor.visit(AnnotationAttributesReadingVisitor.java:122)
at org.springframework.core.type.classreading.AbstractRecursiveAnnotationVisitor.visitEnum(AnnotationAttributesReadingVisitor.java:77)
at org.springframework.asm.ClassReader.a(Unknown Source)
at org.springframework.asm.ClassReader.a(Unknown Source)
at org.springframework.asm.ClassReader.a(Unknown Source)
at org.springframework.asm.ClassReader.a(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:64)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:266)
... 63 more
SampleImpl:-
public class SampleImpl extends AbstractServiceImpl {
/**
* The stack builder to manage the blueprints
*/
protected StackBuilder builder;
protected Sample2ServiceImpl service2;
/**
* The object factory
*/
// DH: remove because it was hiding the same thing in the abstract base class
// protected ObjectFactory objectFactory = new ObjectFactory();
private final static int SAMPLE_VALIDATION_ERROR_CODE = 100;
/**
* Constructor
*/
public SampleImpl() {
}
public SampleImpl(StackBuilderFactory fac, EngineResolver resolver) {
try {
builder = fac.getBuilder();
builder.registerSampleResolver(resolver);
} catch (EngineException e) {
LOG.error("Error initializing SampleImpl", e);
}
}
/**
* Invoked by a BeanFactory after it has set all bean properties. The bean will create an instance of the stack
* builder factory and create a disconnected (not attached to any context) stack builder. A disconnected stack
* builder cannot be used to access any provider services since there is no provider connected. It can still be used
* to validate Samples and process the hierarchy.
*/
public void afterPropertiesSet() throws Exception {
LOG.debug("{}: afterPropertiesSet(): Entered", this);
sbFactory = new StackBuilderFactory();
builder = sbFactory.getBuilder();
builder.registerSampleResolver(getEngineResolver());
service2 = new Sample2ServiceImpl(getDaoProvider());
LOG.debug("{}: afterPropertiesSet(): DONE", this);
}
#AuthorizeOperation(permissionsAuthorized = { Permission.OPERATION_DELETE_Sample })
public void deleteSample(SampleId sampleId) throws UnauthorizedException, EntityNotFoundException,
EntityMappingException, CDPException {
LOG.info("deleting Sample...");
sampleId= getDaoProvider().getSample2Dao().populateSampleIdWithBpId(sampleId);
/**
* Check if the Sample exists
*/
if (StringUtils.isBlank(sampleId.getId())) {
throw new EntityNotFoundException(CDPMsg.REQUESTED_Sample_DOES_NOT_EXIST, sampleId.toString());
}
UUID sampleUUIDId = sampleId.toUUID();
//check if Sample name is System
if (sampleId.getName().equals(com.name.SYSTEM_SAMPLE_NAME)) {
// cannot delete since its System Sample
String msg = "System Sample cannot be deleted";
LOG.error(msg);
throw new EntityMappingException(msg);
}
if(getDaoProvider().getDescendants2Dao().checkSampleIsAncestor(sampleUUIDId )) {
String msg =
Msg.SAMPLE_USED_BY_OTHER_SAMPLE
.getMessage(sampleId.format(sampleId.getId(), sampleId.getName(), sampleId.getVersion()));
LOG.error(msg);
throw new EntityMappingException(CDPMsg.SAMPLE_USED_BY_OTHER_SAMPLE, SampleId.format(sampleId.getId(), sampleId.getName(), sampleId.getVersion()));
}
if (getDaoProvider().getSampleByStack2Dao().checkSampleUsedByStack(sampleId)) {
// cannot delete since its used by stack
String msg = CDPMsg.SAMPLE_USED_BY_STACK.getMessage(SampleId.format(sampleId.getId(), sampleId.getName(), sampleId.getVersion()));
LOG.error(msg);
throw new EntityMappingException(Msg.SAMPLE_USED_BY_STACK, SampleId.format(sampleId.getId(), sampleId.getName(), sampleId.getVersion()));
}
//getDaoProvider().getSampleDao().deleteSample(sampleId.getName(), sampleId.getVersion());
String currentUser = getUserSecurityProvider().getCurrentUserId();
UUID tenantId = getDaoProvider().getBlueprintByTenant2Dao().getTenantIdSampleByTenant(SampleUUIDId);
service2.deleteAllBlueprintTables(sampleUUIDId, tenantId, currentUser);
service2.deleteAncestor2AndDescendant2(sampleUUIDId, currentUser);
getDaoProvider().getSampleByTenant2Dao().delete(sampleUUIDId);
getDaoProvider().getTenantBySample2Dao().delete(tenantId, blueprintUUIDId);
getDaoProvider().getSample2Dao().delete(sampleUUIDId);
LOG.info("deleted Samplesuccessfully");
}
I was reading through a Spring tutorial and came across the following example. It mentioned that Spring supports the Java EE annotation #Resource. I was trying the example with the source below, but it gave an InvocationTargetException. I suppose it was probably due to the SpellChecker object could not be injected properly.
Relevant stacktrace:
Feb 27, 2018 8:56:23 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#5d76b067: startup date [Tue Feb 27 20:56:23 CST 2018];root of context hierarchy
Feb 27, 2018 8:56:32 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitionsINFO: Loading XML bean definitions from class path resource [Beans.xml]
Inside TextEditor constructor.Inside SpellChecker constructor.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.NullPointerException at com.tutorialspoint.TextEditor.spellCheck(TextEditor.java:22) at com.tutorialspoint.MainApp.main(MainApp.java:10)
... 8 more
I attempted with the #Autowired annotation instead of the #Resource annotation, and it gave the expected result:
Inside TextEditor constructor.
Inside SpellChecker constructor.
Inside checkSpelling.
Would like to see if you can kindly advise / point out mistakes if any, thanks a lot.
(Reference:
https://www.tutorialspoint.com/spring/spring_jsr250_annotations.htm)
[TextEditor.java]
import javax.annotation.Resource;
public class TextEditor {
private SpellChecker spellChecker;
public TextEditor() {
System.out.println("Inside TextEditor constructor.");
}
#Resource(name = "spellChecker")
public void setSpellChecker(SpellChecker spellChecker) {
this.spellChecker = spellChecker;
}
public SpellChecker getSpellChecker() {
return spellChecker;
}
public void spellCheck() {
spellChecker.checkSpelling(); //Gave InvocationTargetException here
}
}
[SpellChecker.java]
public class SpellChecker {
public SpellChecker() {
System.out.println("Inside SpellChecker constructor.");
}
public void checkSpelling() {
System.out.println("Inside checkSpelling.");
}
}
[MainApp.java]
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
TextEditor te = (TextEditor) context.getBean("textEditor");
te.spellCheck();
}
}
[Beans.xml]
<?xml version = "1.0" encoding = "UTF-8"?>
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:context = "http://www.springframework.org/schema/context"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
<!-- Definition for textEditor bean without constructor-arg -->
<bean id = "textEditor" name = "textEditor" class = "com.tutorialspoint.TextEditor"></bean>
<!-- Definition for spellChecker bean -->
<bean id = "spellChecker" name = "spellChecker" class = "com.tutorialspoint.SpellChecker"></bean>
</beans>
I'm new to spring and I was trying constructor injection. I get an IllegalArgumentException in the first line of the main function. It does not have problems locating the xml file when I use a property tag inside the xml(setter injection) but here it is raising an exception.
Triangle.java
package myPackage;
public class Triangle
{
private String type;
public Triangle(String type) {
this.type = type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public void draw()
{
System.out.println(getType()+" Triangle Drawn");
}
}
DrawingApp.java
package myPackage;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class DrawingApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
Triangle t = (Triangle) context.getBean("triangle");
t.draw();
}
}
spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="triangle" class="myPackage.Triangle" >
<constructor-arg value="equilateral" />
</bean>
</beans>
These are the errors that I get.
Feb 05, 2018 1:41:14 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#2d8e6db6: startup date [Mon Feb 05 13:41:14 IST 2018]; root of context hierarchy
Feb 05, 2018 1:41:14 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring.xml]
Feb 05, 2018 1:41:14 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#17550481: defining beans [triangle]; root of factory hierarchy
Exception in thread "main" java.lang.IllegalArgumentException
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.inspectClass(LocalVariableTableParameterNameDiscoverer.java:112)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.getParameterNames(LocalVariableTableParameterNameDiscoverer.java:86)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:193)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1049)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:953)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at myPackage.DrawingApp.main(DrawingApp.java:12)
Just a shot in the dark, but do I need a local interface to call a remote stateless EJB?
when I try call the bean remotely through Netbeans:
Netbeans doesn't allow a remote call, or any call, on this bean. Why not?
Trying to do it manually, as below:
What is the jndi global remote name for the Remote EJB which is deployed on glassfish?
INFO: visiting unvisited references
INFO: visiting unvisited references
INFO: EJB5181:Portable JNDI names for EJB MyRemoteSessionClass: [java:global/RemoteSalutation-ejb/MyRemoteSessionClass!net.bounceme.dur.glassfish.MyRemoteSession, java:global/RemoteSalutation-ejb/MyRemoteSessionClass]
INFO: RemoteSalutation-ejb was successfully deployed in 941 milliseconds.
If possible, I would rather specify the class in the properties file rather than hard-coded. In any event, different variations result in a lookup failure. Here's the stack-trace:
run-deploy:
Copying 1 file to /home/thufir/NetBeansProjects/RemoteLookup/dist
Copying 2 files to /home/thufir/NetBeansProjects/RemoteLookup/dist/RemoteLookupClient
Warning: /home/thufir/NetBeansProjects/RemoteLookup/dist/gfdeploy/RemoteLookup does not exist.
Sep 13, 2014 1:35:41 AM net.bounceme.dur.remote.RemoteLookup run
INFO: java.naming.factory.initial com.sun.enterprise.naming.impl.SerialInitContextFactory
Sep 13, 2014 1:35:41 AM net.bounceme.dur.remote.RemoteLookup run
INFO: java.naming.factory.url.pkgs com.sun.enterprise.naming
Sep 13, 2014 1:35:41 AM net.bounceme.dur.remote.RemoteLookup run
INFO: java.naming.factory.state com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
Sep 13, 2014 1:35:46 AM net.bounceme.dur.remote.RemoteLookup main
SEVERE: Lookup failed for ' java:comp/env//RemoteSalutation-ejb/MyRemoteSessionClass!net/bounceme/dur/glassfish/MyRemoteSession' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, remote=net.bounceme.ix.Foo, org.omg.CORBA.ORBInitialHost=localhost, java.naming.security.principal=user, org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.provider.url=server.local:1199, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.security.credentials=password}
javax.naming.NamingException: Lookup failed for ' java:comp/env//RemoteSalutation-ejb/MyRemoteSessionClass!net/bounceme/dur/glassfish/MyRemoteSession' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, remote=net.bounceme.ix.Foo, org.omg.CORBA.ORBInitialHost=localhost, java.naming.security.principal=user, org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.provider.url=server.local:1199, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.security.credentials=password} [Root exception is javax.naming.NameNotFoundException: java:comp]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at net.bounceme.dur.remote.RemoteLookup.run(RemoteLookup.java:34)
at net.bounceme.dur.remote.RemoteLookup.main(RemoteLookup.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:446)
at org.glassfish.appclient.client.AppClientFacade.main(AppClientFacade.java:166)
Caused by: javax.naming.NameNotFoundException: java:comp
at com.sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:299)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:207)
at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:66)
at com.sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
run:
BUILD SUCCESSFUL (total time: 17 seconds)
client code:
package net.bounceme.dur.remote;
import java.util.Enumeration;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class RemoteLookup {
private static final Logger log = Logger.getLogger(RemoteLookup.class.getName());
private final MyProps p = new MyProps();
public static void main(String... args) {
try {
new RemoteLookup().run();
} catch (NamingException ex) {
Logger.getLogger(RemoteLookup.class.getName()).log(Level.SEVERE, ex.getExplanation(), ex);
}
}
private void run() throws NamingException {
Properties jndi = p.getJNDI();
Enumeration e = jndi.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String val = jndi.getProperty(key);
log.info(key + "\t" + val);
}
Context ic = new InitialContext();
// Object o = ic.lookup(" java:comp/env/RemoteSalutation-ejb/MyRemoteSessionClass");
Object o = ic.lookup(" java:comp/env//RemoteSalutation-ejb/MyRemoteSessionClass!net/bounceme/dur/glassfish/MyRemoteSession");
}
}
the remote EJB:
package net.bounceme.dur.glassfish;
import javax.ejb.Stateless;
//#LocalBean
#Stateless(mappedName = "salutationBean")
public class MyRemoteSessionClass implements MyRemoteSession {
#Override
public String SayHello() {
return "hello from glassfish..";
}
#Override
public String SayBye() {
return "goodbye..";
}
}
note that the interface is remote, ie: it's literally a Java class library. Correct? This makes the EJB remote.
referencing:
https://netbeans.org/kb/docs/javaee/entappclient.html
although I changed the names a bit..otherwise should be exactly as the tutorial.
Try Object o = ic.lookup("salutationBean");
Note that mappedName specifies the name to use in JNDI for a remote access.
I am trying to create a sample test application which converts an object to JaxbRepresentation. But when I try to run this, it gives me an error.
Main.java file
package test_jaxb;
import org.restlet.Server;
import org.restlet.data.Protocol;
public class Main {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws Exception {
Server helloServer = new Server(Protocol.HTTP, 8111,
TestResource.class);
helloServer.start();
}
}
TestResource.java file
package test_jaxb;
import org.restlet.ext.jaxb.JaxbRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;
public class TestResource extends ServerResource{
#Override
protected Representation get() throws ResourceException {
SampleResponse res = new SampleResponse();
res.setMsg("Success");
res.setStatusCode(0);
JaxbRepresentation<SampleResponse> representation = new JaxbRepresentation<SampleResponse>(res);
return representation;
}
}
SampleResponse.java file
package test_jaxb;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name="Response")
public class SampleResponse {
private int statusCode;
private String msg;
#XmlElement(name="Msg")
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
#XmlElement(name="StatusCode")
public int getStatusCode() {
return statusCode;
}
public void setStatusCode(int statusCode) {
this.statusCode = statusCode;
}
}
When I run this on the server, it throws the following error:
WARNING: Problem creating Marshaller
javax.xml.bind.JAXBException: "test_jaxb" doesnt contain ObjectFactory.class or jaxb.index
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:119)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:299)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
at org.restlet.ext.jaxb.JaxbRepresentation.getContext(JaxbRepresentation.java:83)
at org.restlet.ext.jaxb.internal.Marshaller$1.initialValue(Marshaller.java:68)
at org.restlet.ext.jaxb.internal.Marshaller$1.initialValue(Marshaller.java:64)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:141)
at java.lang.ThreadLocal.get(ThreadLocal.java:131)
at org.restlet.ext.jaxb.internal.Marshaller.getMarshaller(Marshaller.java:163)
at org.restlet.ext.jaxb.internal.Marshaller.marshal(Marshaller.java:216)
at org.restlet.ext.jaxb.JaxbRepresentation.write(JaxbRepresentation.java:527)
at org.restlet.representation.WriterRepresentation.write(WriterRepresentation.java:104)
at org.restlet.engine.http.connector.Connection.writeMessageBody(Connection.java:873)
at org.restlet.engine.http.connector.Connection.writeMessage(Connection.java:818)
at org.restlet.engine.http.connector.ServerConnection.writeMessage(ServerConnection.java:334)
at org.restlet.engine.http.connector.Connection.writeMessages(Connection.java:954)
at org.restlet.engine.http.connector.BaseServerHelper.handleOutbound(BaseServerHelper.java:201)
at org.restlet.engine.http.connector.BaseHelper.handleNextOutbound(BaseHelper.java:425)
at org.restlet.engine.http.connector.BaseServerHelper.handleInbound(BaseServerHelper.java:174)
at org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
May 16, 2011 7:05:12 AM org.restlet.ext.jaxb.internal.Marshaller getMarshaller
WARNING: Unable to locate marshaller.
May 16, 2011 7:05:12 AM org.restlet.ext.jaxb.JaxbRepresentation write
WARNING: JAXB marshalling error caught.
javax.xml.bind.JAXBException: Unable to locate marshaller.
at org.restlet.ext.jaxb.internal.Marshaller.getMarshaller(Marshaller.java:166)
at org.restlet.ext.jaxb.internal.Marshaller.marshal(Marshaller.java:216)
at org.restlet.ext.jaxb.JaxbRepresentation.write(JaxbRepresentation.java:527)
at org.restlet.representation.WriterRepresentation.write(WriterRepresentation.java:104)
at org.restlet.engine.http.connector.Connection.writeMessageBody(Connection.java:873)
at org.restlet.engine.http.connector.Connection.writeMessage(Connection.java:818)
at org.restlet.engine.http.connector.ServerConnection.writeMessage(ServerConnection.java:334)
at org.restlet.engine.http.connector.Connection.writeMessages(Connection.java:954)
at org.restlet.engine.http.connector.BaseServerHelper.handleOutbound(BaseServerHelper.java:201)
at org.restlet.engine.http.connector.BaseHelper.handleNextOutbound(BaseHelper.java:425)
at org.restlet.engine.http.connector.BaseServerHelper.handleInbound(BaseServerHelper.java:174)
at org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
May 16, 2011 7:05:12 AM org.restlet.ext.jaxb.internal.Marshaller$1 initialValue
WARNING: Problem creating Marshaller
javax.xml.bind.JAXBException: "failure" doesnt contain ObjectFactory.class or jaxb.index
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:119)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:299)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
at org.restlet.ext.jaxb.JaxbRepresentation.getContext(JaxbRepresentation.java:83)
at org.restlet.ext.jaxb.internal.Marshaller$1.initialValue(Marshaller.java:68)
at org.restlet.ext.jaxb.internal.Marshaller$1.initialValue(Marshaller.java:64)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:141)
at java.lang.ThreadLocal.get(ThreadLocal.java:131)
at org.restlet.ext.jaxb.internal.Marshaller.getMarshaller(Marshaller.java:163)
at org.restlet.ext.jaxb.internal.Marshaller.marshal(Marshaller.java:216)
at org.restlet.ext.jaxb.JaxbRepresentation.write(JaxbRepresentation.java:535)
at org.restlet.representation.WriterRepresentation.write(WriterRepresentation.java:104)
at org.restlet.engine.http.connector.Connection.writeMessageBody(Connection.java:873)
at org.restlet.engine.http.connector.Connection.writeMessage(Connection.java:818)
at org.restlet.engine.http.connector.ServerConnection.writeMessage(ServerConnection.java:334)
at org.restlet.engine.http.connector.Connection.writeMessages(Connection.java:954)
at org.restlet.engine.http.connector.BaseServerHelper.handleOutbound(BaseServerHelper.java:201)
at org.restlet.engine.http.connector.BaseHelper.handleNextOutbound(BaseHelper.java:425)
at org.restlet.engine.http.connector.BaseServerHelper.handleInbound(BaseServerHelper.java:174)
at org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
May 16, 2011 7:05:12 AM org.restlet.ext.jaxb.internal.Marshaller getMarshaller
WARNING: Unable to locate marshaller.
May 16, 2011 7:05:12 AM org.restlet.engine.http.connector.Connection writeMessage
WARNING: Exception while writing the message body.
java.io.IOException: Unable to locate marshaller.
at org.restlet.ext.jaxb.JaxbRepresentation.write(JaxbRepresentation.java:539)
at org.restlet.representation.WriterRepresentation.write(WriterRepresentation.java:104)
at org.restlet.engine.http.connector.Connection.writeMessageBody(Connection.java:873)
at org.restlet.engine.http.connector.Connection.writeMessage(Connection.java:818)
at org.restlet.engine.http.connector.ServerConnection.writeMessage(ServerConnection.java:334)
at org.restlet.engine.http.connector.Connection.writeMessages(Connection.java:954)
at org.restlet.engine.http.connector.BaseServerHelper.handleOutbound(BaseServerHelper.java:201)
at org.restlet.engine.http.connector.BaseHelper.handleNextOutbound(BaseHelper.java:425)
at org.restlet.engine.http.connector.BaseServerHelper.handleInbound(BaseServerHelper.java:174)
at org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
May 16, 2011 7:05:12 AM org.restlet.engine.http.connector.ServerConnection writeMessage
INFO: An exception occured while writing the response
java.io.IOException: Unable to locate marshaller.
at org.restlet.ext.jaxb.JaxbRepresentation.write(JaxbRepresentation.java:539)
at org.restlet.representation.WriterRepresentation.write(WriterRepresentation.java:104)
at org.restlet.engine.http.connector.Connection.writeMessageBody(Connection.java:873)
at org.restlet.engine.http.connector.Connection.writeMessage(Connection.java:818)
at org.restlet.engine.http.connector.ServerConnection.writeMessage(ServerConnection.java:334)
at org.restlet.engine.http.connector.Connection.writeMessages(Connection.java:954)
at org.restlet.engine.http.connector.BaseServerHelper.handleOutbound(BaseServerHelper.java:201)
at org.restlet.engine.http.connector.BaseHelper.handleNextOutbound(BaseHelper.java:425)
at org.restlet.engine.http.connector.BaseServerHelper.handleInbound(BaseServerHelper.java:174)
at org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Please someone help!!!
In my case I was able to resolve this by adding a file called "jaxb.index" in the same package folder as the JAXB annotated class. In that file list the simple, non-qualified names of the annotated classes.
For example, my file /MyProject/src/main/java/com/example/services/types/jaxb.index
is simply one line (since I have only one JAXB typed class):
ServerDiagContent
which refers to the class com.example.services.types.ServerDiagContent
I was using Spring and I just had to change
Jaxb2Marshaller mlr = new Jaxb2Marshaller();
mlr.setContextPaths("","");
to
Jaxb2Marshaller mlr = new Jaxb2Marshaller();
mlr.setPackagesToScan("","");
Ref1 & Ref2
To get rid of additional jaxb.index files you may use Java class to instantiate the context:
http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/JAXBContext.html#newInstance(java.lang.Class...)
Usually you need to pass in only single java class because other classes are "statically reachable from these class(es)" so JAXB is able to identify them.
I got this error because of a ClassLoader issue, and I was able to solve it by explicitly passing the ClassLoader that JAXB should use, so this:
JAXBContext.newInstance(com.myexample.test.ObjectFactory.class.getPackage().getName());
gave an error, but worked properly when using:
JAXBContext.newInstance(com.myexample.test.ObjectFactory.class.getPackage().getName(),
com.myexample.test.ObjectFactory.class.getClassLoader());
which is probably similar to user3243752's answer, I bet that JAXB is automatically choosing the ClassLoader from the passed in class when using the #newInstance(Class... classesToBeBound) method signature.
In my case I was able to solve the problem by changing the instantiation of the JAXBContext.
It can either be instantiated with the package name or the ObjectFactory class as a parameter.
When instantiating with the package name:
com.myexample.test.ObjectFactory objectFactory = new com.myexample.test.ObjectFactory();
JAXBContext jaxbContext = JAXBContext.newInstance(objectFactoryMessageBody.getClass().getPackage().getName());
It gave the error:
"com.myexample.test" doesnt contain ObjectFactory.class or jaxb.index
No errors when instantiating with the class name:
com.myexample.test.ObjectFactory objectFactory = new com.myexample.test.ObjectFactory();
JAXBContext jaxbContext = JAXBContext.newInstance(objectFactoryMessageBody.getClass());
If you have an instantiation of your object factory like
private ObjectFactory of;
..then the safest, most reliable way to get a Context to Marshall with is:
JAXBElement<GreetingListType> gl = of.createGreetings( grList );
JAXBContext jc = JAXBContext.newInstance(of.getClass());
Marshaller m = jc.createMarshaller();
Use the complete package name of the where the ObjectFactory class is present to declare and instantiate the Object.
I created an empty jaxb.index file at the location where it was looking for the object factory class. That fixed my problem.
I noticed the package name of payload Java classes where supposed to turn into xXSD file, was wrong at JAXB2 plugin config in PUM file. When I corrected it the problem solved.