Getting the following error in my console
printing ra
Dec 19, 2020 2:19:52 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping for GET /FirstSpringWebExample/WEB-INF/hello.html
My files are as below,
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>FirstSpringWebExample</display-name>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
HelloWeb-servlet.xml
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:context = "http://www.springframework.org/schema/context"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package = "com.sri.controller" />
<bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value = "/WEB-INF/" />
<property name = "suffix" value = ".html" />
</bean>
</beans>
HelloController.java
package com.sri.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
#Controller
public class HelloController {
#RequestMapping(value = "/hello", method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
System.out.println("printing");
return "hello";
}
#RequestMapping(value = "/hellot", method = RequestMethod.GET)
public String printHellos(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
System.out.println("printing ra");
return "hello";
}
}
hello.html
<html>
<head>
<title>Hello Spring MVC</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
Here in above code.Controller is working fine but view is not working.Here it is getting as requested resource not available.
I have changed the html extension to jsp extension.Now it is working (Dont know why InternalViewResolver cant render html page)
Related
In my Spring MVC application, I want to redirect my page from index.jsp page to final.jsp page using AJAX. But the redirected page (final.jsp) is not being displayed when I click the Redirect Page button in my application. I have used System.out.println("inside /redirect"); and System.out.println("inside /finalPage"); inside my Java code to check whether the AJAX GET request is being received at server or not, and only inside /redirect is being printed which which means that the /finalPage is not being called. Moreover, my browser's console does not show any error. So please tell, what can be the problem and where is that problem? I have posted my complete code below:
WebController.java
package com.tutorialspoint;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
#Controller
public class WebController {
#RequestMapping(value = "/index", method = RequestMethod.GET)
public String index() {
return "index";
}
#RequestMapping(value = "/redirect", method = RequestMethod.GET)
public String redirect() {
System.out.println("inside /redirect");
return "redirect:/finalPage";
}
#RequestMapping(value = "/finalPage", method = RequestMethod.GET)
public String finalPage() {
System.out.println("inside /finalPage");
return "final";
}
}
index.jsp
<%#taglib uri = "http://www.springframework.org/tags/form" prefix = "form"%>
<html>
<head>
<title>Spring Page Redirection</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<h2>Spring Page Redirection</h2>
<p>Click below button to redirect the result to new page</p>
<button onClick="redFun()">Redirect Page</button>
<script>
function redFun() {
$.ajax({
type : "GET",
url : "/HelloWeb/redirect"
});
}
</script>
</body>
</html>
final.jsp
<%#taglib uri = "http://www.springframework.org/tags/form" prefix = "form"%>
<html>
<head>
<title>Spring Page Redirection</title>
</head>
<body>
<h2>Redirected Page</h2>
</body>
</html>
web.xml:
<web-app id = "WebApp_ID" 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>Spring MVC Application</display-name>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
HelloWeb-servlet.xml
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:context = "http://www.springframework.org/schema/context"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package = "com.tutorialspoint" />
<bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value = "/WEB-INF/jsp/" />
<property name = "suffix" value = ".jsp" />
</bean>
</beans>
Your browser is not following the redirect because you're using ajax to hit your controller's redirect method. You have two options:
Don't use ajax at all, and let your browser respond naturally to the redirect status.
function redFun() {
window.location = "/HelloWeb/redirect";
}
Look for an HTTP 302 response to the XmlHttpRequest, and change window.location to the value of the Location header in the response:
function redFun() {
$.ajax({
type: "GET",
url: "/HelloWeb/redirect"
}).fail(function (jqXHR, status, err) {
if (jqXHR.status === 302) {
window.location = jqXHR.getResponseHeader('Location');
}
});
}
I am trying to make simple validation form using Hibernate Validator. I have two fields in my Customer class, and i want one of them to be required (lastName).
The point is that even when im not filling this field I am not getting error message and BindingResult does not contain any errors. Is there anything im missing in my code?
Here is my Customer class snippet.
public class Customer {
private String firstName;
#NotNull(message = "is required")
#Size(min = 1, message = "is required")
private String lastName;
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Here is Controller
#Controller
#RequestMapping("/customer")
public class CustomerController {
//adding new customer to model
#RequestMapping("/showForm")
public String showForm(Model theModel){
theModel.addAttribute("customer", new Customer());
return "customer-form";
}
//Validating passed customer attribute/object
//Biding result object holds validation results
#RequestMapping("/processForm")
public String processForm(
#Valid #ModelAttribute("customer") Customer theCustomer, BindingResult theBindingResult) {
if (theBindingResult.hasErrors()){
return "customer-form";
}
return "customer-confirmation";
}
}
EDIT: form code:
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Customer Registration Form</title>
</head>
<body>
<style>
.error{color: red}
</style>
<i> Fill out the form. Asteriks (*) means required. </i>
<br><br>
<form:form action="processForm" modelAttribute="customer">
First name: <form:input path="firstName" />
<br><br>
Last name (*): <form:input path="lastName"/>
<form:errors path="lastName" cssClass="error" />
<input type="submit" value="Submit"/>
</form:form>
</body>
</html>
EDIT 2:
I added to classpath validation-api.jar (contains the abstract API and the annotation scanner).
Also inserted #InitBinnder just to make sure that empty form field will always be null not empty String.
#InitBinder
public void initBinder(WebDataBinder dataBinder) {
StringTrimmerEditor stringTrimmerEditor = new StringTrimmerEditor(true);
dataBinder.registerCustomEditor(String.class, stringTrimmerEditor);
}
But it still seems that those annotations never get triggered at all
EDIT 3: After calling validator on Entity I am getting error:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.validation.NoProviderFoundException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
although i have added it to classpath
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
validator.validate(theCustomer);
EDIT 4: Adding Spring Configuration files:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>mvc-validation-demo</display-name>
<!-- Spring MVC Configs -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-validation-demo.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
mvc-validation-demo.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/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/">
<context:component-scan base-package="com.lobo.mvc" />
<mvc:annotation-driven/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
EDIT 5: According to what #eis said i added to my mvc-validation-demo.xml:
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
And i also have Hibernate Validator in my classpath:
Classpath
but the error still remains
Deleteing .idea , clearing cache and new configuration did the job for me. It seems that somehow it didn't saw hibernate-validator.jar.
Thank you to everyone who contributed.
I have a problem with my application. When I send JSON data I get return error 415 - The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
I am new in this and I still trying understanding this.
JSP page:
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
jQuery(document).ready(function() {
$("#form-temp").submit(function(event) {
event.preventDefault();
searchViaAjax();
});
});
function searchViaAjax() {
var temp = {}
temp["temp"] = $("#temp").val();
$.ajax({
type : "POST",
contentType : "application/json",
url : "/update",
data : JSON.stringify(temp),
dataType : 'json',
cache: false,
timeout: 600000,
success : function(temp) {
console.log("SUCCESS: ", data);
//display(temp);
}
});
}
/* function display(temp) {
var json = "<h4>Ajax Response</h4><pre>"+ JSON.stringify(data, null, 4) + "</pre>";
$('#feedback').html(json);
} */
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Formularz wprowadzania temperatury</title>
</head>
<body>
<form id="form" method="post" action="update" id="form-temp">
<div><label for="temp">Podaj temperaturę</label></div>
<div><input type="text" name="temp" id="temp"/></div>
<div><button id="sendBtn">Dodaj</button></div>
</form>
<form id="form" method="get" action="stats">
<div><button id="sendBtn">Lista temperatur</button></div>
</form>
</body>
</html>
Controller:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import pl.e.rekrutacja.domain.repository.TempRepository;
import pl.e.rekrutacja.model.Temp;
#RestController
public class UpdateController {
#Autowired
private TempRepository tempRepository;
// #ResponseBody
#RequestMapping(value = "/update", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public String startPage(#RequestBody Temp temp){
tempRepository.addTemp(temp);
return "input_form_temp";
}
}
Model class:
public class Temp {
private double value;
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
public Temp(double value) {
super();
this.value = value;
}
}
Application context:
<?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/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<mvc:annotation-driven enable-matrix-variables="true"/>
<context:component-scan base-package="pl.e.rekrutacja" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id= "tempRepositoryImpl" class="pl.e.rekrutacja.domain.repository.impl.TempRepositoryImpl"/>
</beans>
web.xml:
<web-app version="3.0" 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_3_0.xsd">
<filter>
<filter-name>encoding-filter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/webcontext/DispatcherServlet-context.xml
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Your controller is returning a view name to the requested resource. Instead it must return the state of the Temp object in JSON format.
#RequestMapping(value = "/update", method = RequestMethod.POST)
public #ResponseBody Temp tempStartPage(#PathVariable(#RequestBody Temp temp)) {
return tempRepository.addTemp(temp);
}
The #ResponseBody will handle the consumes = "application/json", produces = "application/json" .
This question already has answers here:
What causes "java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute"?
(7 answers)
Closed 6 years ago.
Getting java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute error in spring 3.0. How can I resolve it?
Below is the code for the files
index.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Form handling</title>
</head>
<body>
<form:form action="/emp/showEmployee" method="POST">
<table>
<tbody>
<tr><td>Employee Name: </td><td><form:input path="empName"/></td></tr>
<tr><td>Employee Skill: </td><td><form:input path="empSkill"/></td></tr>
<tr><td><input type="submit" value = "Submit"></td></tr>
</tbody>
</table>
</form:form>
</body>
</html>
web.xml
<web-app 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_3_0.xsd"
version="3.0">
<!-- Processes application requests -->
<servlet>
<servlet-name>emp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>emp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/WEB-INF/views/index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/context-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
context-config.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
EmployeeController.java
package com.springmvctut.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.springmvctut.bean.EmployeeForm;
#Controller
public class EmployeeController {
#RequestMapping(value = "/employee", method = RequestMethod.GET)
public ModelAndView employee() {
return new ModelAndView("employeeForm", "command", new EmployeeForm());
}
#RequestMapping(value = "/showEmployee", method = RequestMethod.POST)
public String showEmployee(#ModelAttribute("SpringWeb")EmployeeForm employeeForm, ModelMap modelMap){
modelMap.addAttribute("name", employeeForm.getEmpName());
modelMap.addAttribute("skill", employeeForm.getEmpSkill());
return "employeedetails";
}
}
EmployeeForm.java(Bean class)
package com.springmvctut.bean;
public class EmployeeForm {
private String empName;
private String empSkill;
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getEmpSkill() {
return empSkill;
}
public void setEmpSkill(String empSkill) {
this.empSkill = empSkill;
}
public String toString(){
return "Employee name-"+empName+" Employee Skill-"+empSkill;
}
}
add this to your form element :
<form:form action="/emp/showEmployee" method="POST" modelAttribute="employee">
update your controller
#ModelAttribute
public void addEmplployeeTomModel(Model model){
model.addAttribute("employee",new EmployeeForm())
}
#RequestMapping(value = "/showEmployee", method = RequestMethod.POST)
public String showEmployee(#ModelAttribute("employee")EmployeeForm employeeForm, ModelMap modelMap){
modelMap.addAttribute("name", employeeForm.getEmpName());
modelMap.addAttribute("skill", employeeForm.getEmpSkill());
return "employeedetails";
}
I'm trying to implement a simple guestbook.
When user clicks "Submit", the UnregisteredUserPost CDI bean is supposed to be instantiated. However, instead I get the following exception:
javax.servlet.ServletException: /guestbook.xhtml #11,57 value="#{unregisteredUserPost.name}": Target Unreachable, identifier 'unregisteredUserPost' resolved to null
I will appreaciate if you help me to find the root cause of the problem.
guestbook.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>#{msg.page_title}</title>
<link rel="stylesheet" type="text/css" href="css.css"/>
</h:head>
<h:body>
<h:form>
<h:outputText value="#{msg.your_name} "/>
<h:inputText value="#{unregisteredUserPost.name}"/>
<br/><br/>
<h:outputText value="#{msg.your_msg}"/>
<br/>
<h:inputTextarea
rows="5" cols="100" value="#{unregisteredUserPost.content}"/>
<br/><br/>
<h:commandButton
value="#{msg.submit}" action="#{unregisteredUserPost}"/>
</h:form>
</h:body>
</html>
UnregisteredUserPost.java
package learning.javaee.guestbook;
import java.time.OffsetDateTime;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
#Named
#SessionScoped
public class UnregisteredUserPost extends AbstractPost {
private String name;
private OffsetDateTime dateTime;
public UnregisteredUserPost() {}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public OffsetDateTime getDateTime() {
return dateTime;
}
public void setDateTime(OffsetDateTime dateTime) {
this.dateTime = dateTime;
}
}
AbstractPost.java
package learning.javaee.guestbook;
import java.io.Serializable;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.interceptor.AroundConstruct;
import javax.interceptor.InvocationContext;
#Named
public abstract class AbstractPost implements Serializable {
private String content;
#Inject
private static Logger log;
#AroundConstruct
private void logConstruction(InvocationContext ic) {
try {
ic.proceed();
log.fine("Created " + getClass().getName());
} catch (Exception e) {
log.severe(e.toString());
}
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID"
version="3.1">
<display-name>guestbook1</display-name>
<welcome-file-list>
<welcome-file>guestbook.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
<resource-bundle>
<base-name>MessagesBundle</base-name>
<var>msg</var>
</resource-bundle>
</application>
</faces-config>
Looks like you're missing bean-discovery-mode="all" in your beans.xml . CDI needs this directive to inject the bean, from your explicit archive.
Related
CDI deployment configuration