0
votes

I have a maven/spring-mvc application which is a very simple web application which calls mvc controller which calls the webservices to get data and gives data to JSP.

I develop this application on my windows machine on eclipse. The application executes perfectly fine. I also executed "maven clean install" through command prompt and create a war file and deployed manually on tomcat 6 and tomcat 7 on windows and this works perfectly fine too.

Now I move the same war file to linux and it gives this error in catalina.out (tomcat log)

`Caused by: org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: com.mondia.entertainment.ws.SecurityServer    
com.mondia.common.controller.HomeController.security; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No matching bean of type [com.mondia.entertainment.ws.SecurityServer] found for dependency: 
expected at least 1 bean which qualifies as autowire candidate for this dependency.    
Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}`

My mvc-dispatcher-servlet.xml looks like this: `

<bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:application.properties" />
</bean>

<!-- enable @Autowired, @Required, @Resource (JSR-250) and other annotations -->
<context:annotation-config />
<context:component-scan base-package="com.mondia.entertainment" />
<context:component-scan base-package="com.mondia.common" />

<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/pages/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

<jaxrs:client id="securityClient"
    serviceClass="com.mondia.entertainment.ws.SecurityServer" address="http://localhost:8080/restful-service/security">
    <jaxrs:features>
        <cxf:logging/>
    </jaxrs:features>
    </jaxrs:client>`

I even moved the apache-tomcat 7 folder (with the war file) from windows to linux and tried to start up the server and I get the same exception.

  1. What does this error imply?
  2. Why does this error not occur on the same instance of tomcat on my windows system?
1
localhost:8080/restful-service/security is this url up and running. If it fails there is a chance of securityClient bean never being created thus the Exception. - shazin
Yes all the URLs work just fine. - user1295300

1 Answers

0
votes

I got this resolved.

The classes where I declare Autowired variables, I need to declare the jaxrs server it depends on using the @DependsOn Annotation.

@Controller
@RequestMapping("/content")
@DependsOn({"entertainmentClient", "securityClient"})
@SessionAttributes("clientAuthToken")
public class ContentController {

@Autowired
ContentServer entertainment;
@Autowired
SecurityServer security;

@RequestMapping("/home")
public ModelAndView someMethod(HttpSession session, @RequestHeader("User-Agent") String userAgent) {
    ModelAndView model = new ModelAndView("channel");
}
}

The xml snippet however didnt need change

<jaxrs:client id="entertainmentClient" serviceClass="com.mondia.entertainment.ws.ContentServer" address="http://rest.getmo.ae/restful-service/entertainment/">
</jaxrs:client>

Well I still fail to understand why the tomcat on windows accepts this code without the @DependsOn Annotation and the same tomcat on Linux gave me an issue. If someone cares to explain it would be great.