I have created a new module (default basicexample )by using Maven Archetype
mvn module-wizard:generate -s settings.xml .
The project structure was generated but when i am trying to access basicexampleService from a controller in omod module basicexampleService.java was defined in api module
using api
Context.getService(BasicExampleService.class);
i am getting an exception
@RequestMapping( value = "/test", method = RequestMethod.GET )
public @ResponseBody String test( ){
try
{
BasicExampleService bs=Context.getService(BasicExampleService.class)
}
catch ( Exception e )
{
e.printStackTrace();
}
return "test";
}
Caused by: java.lang.NoClassDefFoundError: org/openmrs/module/basicexample/api/BasicExampleService
at org.openmrs.module.basicexample.controller.TestController.test21(TestController.java:26)
WebApplicationInitializer
public class Initializer implements WebApplicationInitializer
{
@Override
public void onStartup( final ServletContext servletContext ) throws ServletException
{
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register( CandoApplicationContext.class );
//Context loader listener
servletContext.addListener( new ContextLoaderListener( rootContext ) );
DispatcherServlet dispatcherServlet = new DispatcherServlet( rootContext );
//Dispatcher servlet
ServletRegistration.Dynamic dispatcher =servletContext.addServlet( "dispatcher", dispatcherServlet );
dispatcher.setLoadOnStartup( 1 );
dispatcher.addMapping( "/" );
}
}
Config
@Configuration
@ComponentScan( basePackages = {"org.openmrs.**"} )
@ImportResource( value = { "classpath*:applicationContextservice.xml","classpath*:moduleApplicationContext.xml", "classpath*:webModuleApplicationContext.xml"})
public class CandoApplicationContext extends WebMvcConfigurerAdapter
{
public CandoApplicationContext()
{
System.out.println("test");
}
}
I see that you trying to package the module as a war file. This is not correct. Change back to the default packaging. OpenMRS modules are not packaged as war files. Take a look at this for more module information: https://wiki.openmrs.org/display/docs/Creating+Modules