Я использую Spring и создаю API отдыха. Чтобы загрузить applicationContext. xml, я указал его в web. xml, но он выдает ошибку. Хотя, если я использую ClassPathXmlApplicationContext, то он работает нормально. У меня есть applicationContext в папке web-inf. Пожалуйста, дайте мне знать, если потребуется дополнительная информация.
WEB-INF
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>fr.shiv.quiz.QuizRestAPI</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/quiz/*</url-pattern>
</servlet-mapping>
</web-app>
Resorce
@Path("myresource")
public class MyResource {
@Inject
QuestionDAO questionDAO;
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
* @return String that will be returned as a text/plain response.
*/
@GET
@Path("/questions")
@Produces(MediaType.APPLICATION_JSON)
public List<Question> getIt() {
return questionDAO.getQuestions();
}
}
ERROR
Apr 12, 2020 4:22:33 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Jersey Web Application] in context with path [/QuizRestAPI] threw exception [A MultiException has 3 exceptions. They are:
1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=QuestionDAO,parent=MyResource,qualifiers={},position=-1,optional=false,self=false,unqualified=null,1216705275)
2. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of fr.shiv.quiz.QuizRestAPI.MyResource errors were found
3. java.lang.IllegalStateException: Unable to perform operation: resolve on fr.shiv.quiz.QuizRestAPI.MyResource
] with root cause