0

I have two (web) projects in ways that the second one uses the first extending a class. I don't even know if my project's design is right, but the fact is that I'm facing an error during server start, and I don't know if there's a design mistake:

- ProjectBird

package com.mycompany.dao;

public interface BirdDao{
     public void saveFly(Fly fly);
}

package com.mycompany.dao.impl;

public class BirdDaoImpl implements BirdDao{
   public BirdDaoImpl(){
   }
   public void saveFly(Fly fly){
       System.out.println("I'm saving flight data...");
   }
}

- ProjectFalcon

package com.mycompany.myunit.dao;

public interface FalconDao {
  public void saveHunt(Hunt hunt);
}

package com.mycompany.myunit.dao.impl;

import com.mycompany.dao.impl.BirdDaoImpl;

public class FalconDaoImpl extends BirdDaoImpl implements FalconDao{
  public FalconDaoImpl(){
  }

  public void saveHunt(Hunt hunt){
     System.out.println("I'm saving hunt data... poor prey!");
  }
}

When I try to run this schema on server, Spring raises an exception:

Platform: Eclipse Luna 4.4 Spring Tool Suite 3.6.1

Severe: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.mycompany.myunit.dao.impl.FalconDaoImpl; nested exception is java.io.FileNotFoundException: class path resource [com/mycompany/dao/impl/BirdDaoImpl.class] cannot be opened because it does not exist
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:162)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:305)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    at javax.servlet.GenericServlet.init(GenericServlet.java:241)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.io.FileNotFoundException: class path resource [com/mycompany/dao/impl/BirdDaoImpl.class] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:50)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:82)
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:77)
    at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:564)
    at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getSuperClass(ConfigurationClassParser.java:740)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:287)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:218)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:176)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:158)
    ... 39 more

Is there a design error or would it be an configuration mistake on Eclipse?

  • ProjectBird is listed in POM
  • There's no errors or issues on Eclipse during design time

Thanks!

Alex
  • 3,325
  • 11
  • 52
  • 80
  • How is ProjectBird packaged ? And are you seeing the corresponding dependency within the ProjectFalcon dependencies list ? – m4rtin Sep 17 '14 at 22:22
  • @m4rtin, it's packaged as a jar, since I've installed it as a maven artifact in my .m2 repository.It appears under Maven's dependencies, not as a jar, but as a Project. – Alex Sep 19 '14 at 14:04
  • If it's packaged as a JAR, I think it would be cleaner to include this dependency of your ProjectFalcon as a JAR and not a Project. I could be wrong but the thing with having it as Project is that you have to make sure the sources are properly attached which doesn't seem to be the case given your *FileNotFoundException*. – m4rtin Sep 19 '14 at 14:17
  • @m4rtin, actually I've created an jar from ProjectBird throught Maven, and imported it as an dependency in ProjectFalcon's POM file: com.mycompany project-bird 1.0.0-SNAPSHOT --> – Alex Sep 19 '14 at 15:01
  • Well I think it should work, also since it was imported as a JAR, you can definitely remove the ProjectBird Project dependency in ProjectFalcon. Did you imported the ProjectBird JAR manually or did you published it to your local maven repo and let maven imported it to your ProjectFalcon's dependencies ? If the latter, I'm afraid I'm out of idea :| – m4rtin Sep 19 '14 at 15:08
  • Yes, it was the latter. That's the motive why I've decided to post in Stackoverflow. To worse things, I've not set ProjectBird in the build path. Eclipse seems to be doing it automatically when POM is read. There's no project-bird.jar in Maven's dependencies root structure in Package Explorer, but rather ProjectBird's folder. I know that there's an explanation, but I couldn't discover what is it neither overcome issue yet. – Alex Sep 19 '14 at 15:19
  • I have a tip that sth like importing beans configuration may be the issue, like in http://stackoverflow.com/questions/5113579/how-to-import-spring-config-xml-of-one-project-into-spring-config-xml-of-another . But I've been trying to import mvc-config.xml from ProjectBird without success. – Alex Sep 19 '14 at 18:12
  • Maybe but I would more be searching for the reason why Eclipse obstinately includes ProjectBird's folder as a dependency rather than the JAR. I mean, you could totally have built those projects in different places, even different computers. Try to open the JAR, see if you can find the BirdDaoImpl class, then move the ProjectBird folder to another place where Eclipse cannot put its hands on it (in order to somehow "force" it to run ProjectFalcon with the ProjectBird JAR dependency). – m4rtin Sep 20 '14 at 10:01

1 Answers1

0

In fact the this design will not work well ...

If you have not indicated in some configuration the dependency between projects, it will not work, even so, establish dependency between two web projects sounds not good..

If you need re-use one class or extend one used by other project this scenario is perfect to enclose that class/classes into one jar as dependency and import that unique dependency in both projects.

The more clear example is when you have service layer and web layer, we can put the web layer (http controller and views) in one project and put the service layer (services interfaces and implementations) in other one, and establish a dependency relation between web project and the service project, it could be done by importing the jar as dependency in the web project or declaring it as dependency if we are using maven for example.

jastonitas
  • 51
  • 1
  • 8
  • In this earlier moment, ProjectBird is being used just as a jar. It's not running as a web project. But I've apreciated your suggestion, maybe I'm going to split project in a service and two webprojects. But your answer didn't mentioned the motives why Spring is not locating class BirdDaoImpl. Thanks! – Alex Sep 19 '14 at 14:19