I have run into this "WELD-001408 Unsatisfied dependencies for type [Injector] with qualifiers..." error when deploying a Maven project to Glassfish 4. I searched on the internet and added scope, added bean-discovery-mode="all", all other things and still could not get it work. I am learning Spring Framework and Java EE. Would someone please take a look at my code and help me out? Thanks!
stacktrace:
2014-01-28T11:29:44.755-0600|SEVERE: Exception while loading the app
2014-01-28T11:29:44.755-0600|SEVERE: Undeployment failed for context /MessageBoard
2014-01-28T11:29:44.786-0600|SEVERE: Exception while loading the app : CDI deployment failure:Exception List with 2 exceptions:
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Injector] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Inject org.eclipse.sisu.inject.DefaultBeanLocator.autoPublish(Injector)]
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:403)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:325)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:177)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:208)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:519)
at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:505)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:480)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:536)
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:216)
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:328)
codes:
package com.aaa.chapter5;
public class MessageBoardServiceImpl implements MessageBoardService {
private Map<Long, Message> messages = new LinkedHashMap<Long, Message>();
public List<Message> listMessages() {
return (List)messages.values();
}
public synchronized void postMessages(Message message) {
Long id = System.currentTimeMillis();
message.setId(id);
messages.put(id, message);
}
}
package com.aaa.chapter5.web;
// Bind controller to URL /reservationForm
// initial view will be resolved to the name returned in the default GET method
@Controller
@RequestMapping("/messagePost*")
@RequestScoped
//@SessionAttributes("message") // Command name class was used in earlier Spring versions
public class MessagePostController {
private MessageBoardService messageBoardService;
@Autowired
public void MessagePostController(MessageBoardService messageBoardService) {
this.messageBoardService = messageBoardService;
}
// Controller will always look for a default GET method to call first, irrespective of name
// In this case, named setupForm to ease identification
@RequestMapping(method = RequestMethod.GET)
public String setupForm(Model model) {
// Create inital message object
Message message = new Message();
// Add message to model so it can be display in view
model.addAttribute("message", message);
return "messagePost";
}
@RequestMapping(method = RequestMethod.POST)
public String onSubmit(@ModelAttribute("message") Message message, BindingResult result) { //, SessionStatus status) {
if (result.hasErrors()) {
// Errors, return to Form view
return "messagePost";
} else {
// No errors make reservation
messageBoardService.postMessages(message);
// Set complete, mark the handler's session processing as complete
// Allowing for cleanup of session attributes.
//status.setComplete();
// Redirect to reservationSuccess URL, defined in ReservationSuccessController
return "redirect:messageList";
}
}
}
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aaa.chapter5</groupId>
<artifactId>MessageBoard</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>MessageBoard Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<glassfish.directory>C:/Tools/glassfish4/glassfish</glassfish.directory>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>3.0-alpha-2</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<version>2.1</version>
<type>maven-plugin</type>
</dependency>
web.xml
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/board-service.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>board</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>board</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
board-service.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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.aaa.chapter5" />
<mvc:annotation-driven />
board-servlet.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-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.aaa.chapter5.web"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
<bean id="messageBoard"
class="com.aaa.chapter5.MessageBoardServiceImpl">
</bean>
</beans>