The origin server did not find a current representation for the target resource in Spring rest project and mongodb - spring

I have an issue with my project with a rest app running on tomcat 9, if I type any request for example http://localhost:8080/appmvc/service/hello or http://localhost:8080/appmvc/service/list the server return " The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."
Could someone please tell me what i'm missing?I'will appreciate so much any help
here the server also after the requests
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server version name: Apache Tomcat/9.0.46
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server built: May 8 2021 17:35:52 UTC
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server version number: 9.0.46.0
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: OS Name:
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: OS Version:
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Architecture:
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Java Home: C:\Program Files\RedHat\java-11-openjdk-11.0.11-1
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: JVM Version: 11.0.11+9-LTS
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: JVM Vendor: Red Hat, Inc.
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: CATALINA_BASE: C:\Users\user\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: CATALINA_HOME: C:\Users\user\Desktop\apache-tomcat-9.0.46\apache-tomcat-9.0.46
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dcatalina.base=C:\Users\user\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dcatalina.home=C:\Users\user\Desktop\apache-tomcat-9.0.46\apache-tomcat-9.0.46
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dwtp.deploy=C:\Users\user\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
giu 21, 2022 8:20:21 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dfile.encoding=Cp1252
giu 21, 2022 8:20:21 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMAZIONI: The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [C:\Program Files\RedHat\java-11-openjdk-11.0.11-1\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\VMware\VMware Player\bin\;C:\Python27;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\RedHat\java-1.8.0-openjdk-1.8.0.292-2\bin;C:\Program Files\RedHat\java-1.8.0-openjdk-1.8.0.292-2\jre\bin;C:\Program Files\RedHat\java-11-openjdk-11.0.11-1\bin;C:\Program Files (x86)\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Cassandra\apache cassandra\bin;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\user\AppData\Local\Microsoft\WindowsApps;C:\Users\user\AppData\Roaming\npm;C:\Users\user\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\user\mongosh\;C:\Program Files (x86)\Nmap;C:\Program Files\gradle-7.4.2\bin;;.]
giu 21, 2022 8:20:22 AM org.apache.coyote.AbstractProtocol init
INFORMAZIONI: Initializing ProtocolHandler ["http-nio-8080"]
giu 21, 2022 8:20:23 AM org.apache.catalina.startup.Catalina load
INFORMAZIONI: Server initialization in [2069] milliseconds
giu 21, 2022 8:20:23 AM org.apache.catalina.core.StandardService startInternal
INFORMAZIONI: Starting service [Catalina]
giu 21, 2022 8:20:23 AM org.apache.catalina.core.StandardEngine startInternal
INFORMAZIONI: Starting Servlet engine: [Apache Tomcat/9.0.46]
giu 21, 2022 8:20:24 AM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
AVVERTENZA: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [949] milliseconds.
giu 21, 2022 8:20:28 AM org.apache.jasper.servlet.TldScanner scanJars
INFORMAZIONI: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
giu 21, 2022 8:20:28 AM org.apache.catalina.core.ApplicationContext log
INFORMAZIONI: No Spring WebApplicationInitializer types detected on classpath
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
giu 21, 2022 8:20:29 AM org.apache.catalina.core.ApplicationContext log
INFORMAZIONI: Initializing Spring DispatcherServlet 'rest'
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
giu 21, 2022 8:20:33 AM org.apache.coyote.AbstractProtocol start
INFORMAZIONI: Starting ProtocolHandler ["http-nio-8080"]
giu 21, 2022 8:20:33 AM org.apache.catalina.startup.Catalina start
INFORMAZIONI: Server startup in [10108] milliseconds
my POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zetcode</groupId>
<artifactId>appmvc</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-framework-bom -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>5.3.13</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-core -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>4.4.0-beta2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-core</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.14.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.31</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
web.xm
<?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_4_0.xsd" version="4.0">
<display-name>SpringServiceSample</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
rest-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
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">
<context:component-scan base-package="com.myspringmvc.appmvc.controller" />
<mvc:annotation-driven />
<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
applicatin-config.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:p="http://www.springframework.org/schema/p" xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
<mongo:mongo-client id="mongoClient" host="localhost" port="27017"/>
<mongo:db-factory id="mongoDbFactory" dbname="ecommerce" mongo-client-ref="mongoClient" />
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory" />
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<mongo:repositories base-package="repository mongo-template-ref="mongoTemplate" />
</beans>
SpringServiceController.java
package com.myspringmvc.appmvc.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
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 model.Product;
import repository.ProductRepository;
#RestController
#RequestMapping("/service/")
public class SpringServiceController {
#Autowired
ProductRepository productRepository;
#RequestMapping(value = "/hello", method = RequestMethod.GET)
public String getGreeting() {
String result="Hello ";
return result;
}
#RequestMapping(value="/list", method=RequestMethod.GET)
public List<Product> listAll() {
return productRepository.findAll();
}
#RequestMapping(value="/add", method=RequestMethod.POST)
public Product saveProduct(#RequestBody Product p) {
List<Product> pl=productRepository.findByName(p.getName());
if(!pl.isEmpty()){
return null;
}
productRepository.save(p);
return p;
}
}
ProductRepository.java
package repository;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
import model.Product;
public interface ProductRepository extends MongoRepository<Product, String>{
public List<Product> findByName(String name);
public List<Product> findAll();
}
Product.java
package model;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
#Document(collection = "products")
public class Product {
#Id
private String id;
private String name;
private int quantity;
private float price;
private Category category;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Product(String id, String name, int quantity, float price, Category category) {
super();
this.id = id;
this.name = name;
this.quantity = quantity;
this.price = price;
this.category = category;
}
public Product() {
super();
// TODO Auto-generated constructor stub
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
#Override
public String toString() {
return "Product [id=" + id + ", name=" + name + ", quantity=" + quantity + ", price=" + price + ", category="
+ category + "]";
}
}
Category.java
package model;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
#Document(collection="category")
public class Category {
#Id
private long categoryId;
private String name;
#Field("desc")
private String description;
public long getCategorId() {
return categoryId;
}
public void setCategoryId(long categorId) {
this.categoryId = categorId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

Related

Spring c-namespace issue - Constructor argument '_street' specifies an invalid integer

I am trying out the use of c-namespace while injecting literal values into a constructor. I am running into an issue if I refer to the constructor argument by its name. If I refer to it by the position (i.e. 0,1,2...) it works perfectly fine.
I have set the variable debugging check in eclipse (I am using STS) - Windows > Preferences > Java > Compiler > Add variable attributes to generated class files but I still see the same issue
Below is my code -
Interface
package com.nilaysundarkar.spring.demos;
public interface Person {
public void speak();
}
Implementation
package com.nilaysundarkar.spring.demos;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.inject.Named;
#Component
#Named("Russland")
public class Russian implements Person, BeanNameAware {
private String language = "Russian";
private Address address;
#Autowired
public Russian(Address address){
this.address = address;
}
public void speak() {
System.out.println("I am a Person. I speak " + language + ".");
System.out.println("I stay at " + address + ".");
}
public void setBeanName(String beanName) {
System.out.println(beanName + " has been initialized.");
}
}
Address class
package com.nilaysundarkar.spring.demos;
public class Address {
private String street;
public Address(String street){
this.street = street;
}
public String toString(){
return street;
}
}
Bootstrapping the context -
package com.nilaysundarkar.spring.demos;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class App {
public static void main(String[] args) {
ApplicationContext context = new FileSystemXmlApplicationContext("beans.xml");
Person person = context.getBean(Person.class);
person.speak();
((FileSystemXmlApplicationContext) context).close();
}
}
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:c="http://www.springframework.org/schema/c"
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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.nilaysundarkar.spring.demos"/>
<!-- Works -->
<!--<bean id="address" class="com.nilaysundarkar.spring.demos.Address" c:_0="200 Baker Street" />-->
<!-- Does'nt Work -->
<bean id="address" class="com.nilaysundarkar.spring.demos.Address" c:_street="200 Baker Street" />
</beans>
Error when run with c:_street -
Mar 25, 2017 1:39:44 PM org.springframework.context.support.FileSystemXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext#179d3b25: startup date [Sat Mar 25 13:39:44 EDT 2017]; root of context hierarchy
Mar 25, 2017 1:39:44 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [C:\Users\Nilay\Documents\workspace-sts-3.8.3.RELEASE\demos\beans.xml]
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Constructor argument '_street' specifies an invalid integer
Offending resource: file [C:\Users\Nilay\Documents\workspace-sts-3.8.3.RELEASE\demos\beans.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:72)
at org.springframework.beans.factory.xml.SimpleConstructorNamespaceHandler.decorate(SimpleConstructorNamespaceHandler.java:111)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateIfRequired(BeanDefinitionParserDelegate.java:1448)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateBeanDefinitionIfRequired(BeanDefinitionParserDelegate.java:1427)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateBeanDefinitionIfRequired(BeanDefinitionParserDelegate.java:1415)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.processBeanDefinition(DefaultBeanDefinitionDocumentReader.java:301)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:190)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:169)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:142)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:613)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at com.nilaysundarkar.spring.demos.App.main(App.java:9)
When run with c:_0
Mar 25, 2017 1:42:35 PM org.springframework.context.support.FileSystemXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext#179d3b25: startup date [Sat Mar 25 13:42:35 EDT 2017]; root of context hierarchy
Mar 25, 2017 1:42:35 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [C:\Users\Nilay\Documents\workspace-sts-3.8.3.RELEASE\demos\beans.xml]
Mar 25, 2017 1:42:36 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
Russland has been initialized.
I am a Person. I speak Russian.
I stay at 200 Baker Street.
Mar 25, 2017 1:42:36 PM org.springframework.context.support.FileSystemXmlApplicationContext doClose
INFO: Closing org.springframework.context.support.FileSystemXmlApplicationContext#179d3b25: startup date [Sat Mar 25 13:42:35 EDT 2017]; root of context hierarchy
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nilaysundarkar.spring</groupId>
<artifactId>demos</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
</dependencies>
</project>
The correct way would be to use c:street and not c:_street, as the value after c: prefix must match the constructor parameter name.

2023 [localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping not load when running tomcat

How to config for loading this package
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.
When i run Tomcat everything i got only as below:
0 [localhost-startStop-1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
65 [localhost-startStop-1] INFO org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Fri Mar 11 21:55:33 EET 2016]; root of context hierarchy
366 [localhost-startStop-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
470 [localhost-startStop-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-data.xml]
836 [localhost-startStop-1] INFO org.springframework.context.support.PropertySourcesPlaceholderConfigurer - Loading properties file from URL [file:/Volumes/Data/JavaEE/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/d14-spring_mvc/WEB-INF/classes/db_connection.properties]
1045 [localhost-startStop-1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1042 ms
So i got problem about DispatcherServlet can't find mapping uri with servlet.
1735055 [http-nio-8001-exec-5] WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/vietjob/tyopaikka.lista] in DispatcherServlet with name 'vietjob'
pom.xlm
<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>vjb.de</groupId>
<artifactId>vietjob</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>vietjob Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>4.0.0.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.jumpmind.symmetric.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.3.Final</version>
</dependency>
</dependencies>
<build>
<finalName>vietjob</finalName>
</build>
</project>
servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<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" 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">
<!-- Configures the #Controller programming model -->
<mvc:annotation-driven />
<context:component-scan base-package="vjb.de.vietjob" />
<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views
directory -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- Forwards requests to the "/" resource to the "welcome" view -->
<mvc:view-controller path="/" view-name="index" />
<!-- location of static content (images, js and css files) -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:lang" />
<property name="defaultEncoding" value="UTF-8"/>
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
</mvc:interceptors>
</beans>
Controller
package vjb.de.vietjob.controller;
import java.util.List;
import javax.inject.Inject;
import javax.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
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.bind.annotation.RequestParam;
import vjb.de.vietjob.bean.Duuni;
import vjb.de.vietjob.bean.EhdokasImpl;
import vjb.de.vietjob.dao.DuuniDao;
#Controller
#RequestMapping(value = "/")
public class DuuniController {
#Inject
private DuuniDao duunidao;
public DuuniDao getDuuniDao() {
return this.duunidao;
}
public void setDuuniDao(DuuniDao duunidao) {
this.duunidao = duunidao;
}
// Metodi näyttä kaikki työpaikat, jotka ovat oleva tietokannasta
#RequestMapping(value = "/tyopaikka.lista", method = RequestMethod.GET)
public String showDuuni(Model model) {
List<Duuni> duunit = duunidao.showDuuni();
model.addAttribute("duunit", duunit);
return "duuni/tyopaikka";
}
// Metodi kotisivulle
#RequestMapping(value = "/", method = RequestMethod.GET)
public String returnIndex() {
return "index";
}
// Metodi näyttää lisätietoja työpaikasta
#RequestMapping(value = "/tyopaikka.lista/{id}", method = RequestMethod.GET)
public String showYksiDuuni(
#RequestParam(value = "id", required = false) Integer id,
Model model) {
Duuni duuni = duunidao.showYksiDuuni(id);
model.addAttribute("duuni", duuni);
return "duuni/yksipaikka";
}
// Metodi luo uusi ehdokkaan lomake
#RequestMapping(value = "lomake.luo", method = RequestMethod.POST)
public String getUusiEhdokas(
#ModelAttribute(value = "ehdokas") #Valid EhdokasImpl ehdokas,
BindingResult result) {
return "lomake/ehdokas_lomake";
}
}
Controller modify
package vjb.de.vietjob.controller;
import java.util.List;
import javax.inject.Inject;
import javax.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
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.bind.annotation.RequestParam;
import vjb.de.vietjob.bean.Duuni;
import vjb.de.vietjob.bean.EhdokasImpl;
import vjb.de.vietjob.dao.DuuniDao;
#Controller
/*#RequestMapping(value = "/")*/
public class DuuniController {
#Inject
private DuuniDao duunidao;
public DuuniDao getDuuniDao() {
return this.duunidao;
}
public void setDuuniDao(DuuniDao duunidao) {
this.duunidao = duunidao;
}
// Metodi näyttä kaikki työpaikat, jotka ovat oleva tietokannasta
#RequestMapping(value = "tyopaikka.lista", method = RequestMethod.GET)
public String showDuuni(Model model) {
List<Duuni> duunit = duunidao.showDuuni();
model.addAttribute("duunit", duunit);
return "duuni/tyopaikka";
}
#RequestMapping(value = "/tyopaikka.lista", method = RequestMethod.GET)
public String showDuuni1(Model model) {
List<Duuni> duunit = duunidao.showDuuni();
model.addAttribute("duunit", duunit);
return "duuni/tyopaikka";
}
#RequestMapping(value = "vietjob/tyopaikka.lista", method = RequestMethod.GET)
public String showDuuni2(Model model) {
List<Duuni> duunit = duunidao.showDuuni();
model.addAttribute("duunit", duunit);
return "duuni/tyopaikka";
}
#RequestMapping(value = "/vietjob/tyopaikka.lista", method = RequestMethod.GET)
public String showDuuni3(Model model) {
List<Duuni> duunit = duunidao.showDuuni();
model.addAttribute("duunit", duunit);
return "duuni/tyopaikka";
}
// Metodi kotisivulle
#RequestMapping(value = "/", method = RequestMethod.GET)
public String returnIndex() {
return "index";
}
}
Your controller class has a top level #RequestMapping("/"), try changing that to #RequestMapping("/vietjob").

How to Autowired properties file to Environment variable?

My maven project fail to autowired my properties file into Environment variable. I am using spring 4.2.3.
This is the error when I run maven:test
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#57e1b0c: startup date [Sun Dec 20 08:55:34 PST 2015]; root of context hierarchy
Dec 20, 2015 8:55:34 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from URL [file:/home/bryan-1/workspace/2015dec_riot/test/target/test-classes/applicationContext.xml]
Dec 20, 2015 8:55:34 AM org.springframework.context.support.PropertySourcesPlaceholderConfigurer loadProperties
INFO: Loading properties file from class path resource [application.it.properties]
Dec 20, 2015 8:55:34 AM org.springframework.context.support.ClassPathXmlApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'JMSProperties' defined in file [/home/bryan-1/workspace/2015dec_riot/test/target/classes/test/JMSProperties.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [test.JMSProperties$$EnhancerBySpringCGLIB$$b873400b]: Constructor threw exception; nested exception is java.lang.NullPointerException
This is my applicationContext.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"
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"
xmlns:context="http://www.springframework.org/schema/context">
<context:component-scan base-package="test" />
<context:property-placeholder location="classpath:/application.it.properties" />
<!-- bean definitions here -->
</beans>
This is my properties class:
#Configuration
public class JMSProperties {
....
#Autowired
private Environment env;
public JMSProperties() {
....
}
....
}
This is the Test case generated by Maven by default:
public class AppTest
extends TestCase
{
#Autowired
JMSProperties properties;
private static final Logger logger = LoggerFactory.getLogger(AppTest.class);
AbstractApplicationContext context = new ClassPathXmlApplicationContext("classpath*:/applicationContext.xml");
/**
* Create the test case
*
* #param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* #return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
logger.info(properties.getMatchMakerPassword());
}
}
My Dependences:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<!-- logging framework dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-ext</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
Since the exception is a NPE in the constructor of JMSProperties, it would help to know what is your code there. Your post if not very helpful:
public JMSProperties() {
....
}
My guess is that you try to use env in there. At this point env in null, because spring has to instantiate the class first, and then inject the fields. Hence the NPE.

integration jsf,spring,hibernate: can't call bean in jsf file

I'm working on a project using maven,hibernate,spring and jsf(primefaces). I have a problem with the beans. In the xhtml file i can't call the bean , it doesn't recognise it. for example :value="#{collaborateurBean.listeCollaborateurs}. when i try to call it, it doesn't work. Here i just wrote even though it doesn't appear.
It seems like everything that i did is good but i don't know what i'm missing.
when i run collaborateur.xhtml i get an empty datatable.
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>ma.ensa</groupId>
<artifactId>Projet_sqli</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Projet_sqli Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.8-02</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.8-02</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>start</artifactId>
<version>1.11.2</version>
</dependency>
</dependencies>
<build>
<finalName>Projet_sqli</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
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" version="3.1">
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
faces-config.xml
<?xml version="1.0"?>
<faces-config version="2.2"
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">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
</faces-config>
applicationContext.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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="view">
<bean class="org.primefaces.spring.scope.ViewScope"/>
</entry>
</map>
</property>
</bean>
<context:annotation-config/>
<context:component-scan base-package="dao"/>
<context:component-scan base-package="model"/>
<context:component-scan base-package="controller"/>
</beans>
collaborateur.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body style="background-color: #ECF3FD;">
<h:form id="form">
<p:dataTable id="display" var="listeCollaborateurs" value="#{collaborateurBean.listeCollaborateurs}" editable="true" style="margin-bottom:10px">
<f:facet name="header">
Liste des collaborateurs
</f:facet>
<p:column headerText="Id Collaborateur">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{listeCollaborateurs.idCollaborateur}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="#{listeCollaborateurs.idCollaborateur}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Raison sociale">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{listeCollaborateurs.cin}" /></f:facet>
<f:facet name="input"><p:inputText value="#{listeCollaborateurs.cin}" style="width:100%" label="Year"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="RIB">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{listeCollaborateurs.nom}" /></f:facet>
<f:facet name="input"><p:inputText value="#{listeCollaborateurs.nom}" style="width:100%" label="Year"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Adresse">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{listeCollaborateurs.prenom}" /></f:facet>
<f:facet name="input"><p:inputText value="#{listeCollaborateurs.prenom}" style="width:100%" label="Year"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Date de naissance">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{listeCollaborateurs.dateNaissance}" /></f:facet>
<f:facet name="input"><p:inputText value="#{listeCollaborateurs.dateNaissance}" style="width:100%" label="Year"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Téléphone">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{listeCollaborateurs.telephone}" /></f:facet>
<f:facet name="input"><p:inputText value="#{listeCollaborateurs.telephone}" style="width:100%" label="Year"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Email">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{listeCollaborateurs.email}" /></f:facet>
<f:facet name="input"><p:inputText value="#{listeCollaborateurs.email}" style="width:100%" label="Year"/></f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
CollaborateurBean.java
package controller;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import model.CollaborateurMetier;
import net.vo.Collaborateur;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
#Component
#Scope("view")
public class CollaborateurBean implements java.io.Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
#Autowired
private CollaborateurMetier collaborateurMetier;
private List<Collaborateur> listeCollaborateurs;
private int idCollaborateur;
private String cin;
private String nom;
private String prenom;
private Date dateNaissance;
private String telephone;
private String email;
#PostConstruct
public void init() {
listeCollaborateurs = collaborateurMetier.getAllCollaborateurs();
}
public CollaborateurMetier getCollaborateurMetier() {
return collaborateurMetier;
}
public void setCollaborateurMetier(CollaborateurMetier collaborateurMetier) {
this.collaborateurMetier = collaborateurMetier;
}
public List<Collaborateur> getListeCollaborateurs() {
return listeCollaborateurs;
}
public void setListeCollaborateurs(List<Collaborateur> listeCollaborateurs) {
this.listeCollaborateurs = listeCollaborateurs;
}
public int getIdCollaborateur() {
return idCollaborateur;
}
public void setIdCollaborateur(int idCollaborateur) {
this.idCollaborateur = idCollaborateur;
}
public String getCin() {
return cin;
}
public void setCin(String cin) {
this.cin = cin;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public Date getDateNaissance() {
return dateNaissance;
}
public void setDateNaissance(Date dateNaissance) {
this.dateNaissance = dateNaissance;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
org.primefaces.spring.scope.ViewScope
package org.primefaces.spring.scope;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;
public class ViewScope implements Scope {
public Object get(String name, ObjectFactory objectFactory) {
Map<String,Object> viewMap = FacesContext.getCurrentInstance().getViewRoot().getViewMap();
if(viewMap.containsKey(name)) {
return viewMap.get(name);
} else {
Object object = objectFactory.getObject();
viewMap.put(name, object);
return object;
}
}
public Object remove(String name) {
return FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove(name);
}
public String getConversationId() {
return null;
}
public void registerDestructionCallback(String name, Runnable callback) {
//Not supported
}
public Object resolveContextualObject(String key) {
return null;
}
}
CollaborateurDao
package dao;
import java.util.List;
import net.vo.Collaborateur;
public interface CollaborateurDao {
#SuppressWarnings("rawtypes")
public List getAllCollaborateurs();
}
CollaborateurHibernateDao.java
package dao;
import java.util.List;
import net.vo.Collaborateur;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.stereotype.Repository;
#Repository
public class CollaborateurHibernateDao implements CollaborateurDao{
private List<Collaborateur> listeCollaborateurs;
private Collaborateur collaborateur;
public void init()
{
System.out.println("Méthode d'initiation");
}
#SuppressWarnings({ "unchecked", "rawtypes" })
#Override
public List getAllCollaborateurs() {
Session session=HibernateUtil.getSession();
try
{
session.beginTransaction();
Query q = session.createQuery("from Collaborateur");
listeCollaborateurs = q.list();
System.out.println(listeCollaborateurs.size());
return listeCollaborateurs;
}
catch(HibernateException e)
{
throw e;
}
finally
{
session.close();
}
}
}
CollaborateurMetier.java
package model;
import java.util.List;
import net.vo.Collaborateur;
public interface CollaborateurMetier {
public List<Collaborateur> getAllCollaborateurs();
}
CollaborateurMetierImpl.java
package model;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import dao.CollaborateurDao;
import net.vo.Collaborateur;
#Service
public class CollaborateurMetierImpl implements CollaborateurMetier{
#Autowired
private CollaborateurDao collaborateurDao;
#SuppressWarnings("unchecked")
#Override
public List<Collaborateur> getAllCollaborateurs()
{
return collaborateurDao.getAllCollaborateurs();
}
public void setCollaborateurDao(CollaborateurDao collaborateurDao) {
this.collaborateurDao = collaborateurDao;
}
public CollaborateurDao getCollaborateurDao() {
return collaborateurDao;
}
}
Collaborateur.java
package net.vo;
// Generated 22 nov. 2014 20:53:37 by Hibernate Tools 4.3.1
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* Collaborateur generated by hbm2java
*/
#Entity
#Table(name = "collaborateur", catalog = "formation")
public class Collaborateur implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int idCollaborateur;
private String cin;
private String nom;
private String prenom;
private Date dateNaissance;
private String telephone;
private String email;
public Collaborateur() {
}
public Collaborateur(int idCollaborateur, String cin) {
this.idCollaborateur = idCollaborateur;
this.cin = cin;
}
public Collaborateur(int idCollaborateur, String cin, String nom,
String prenom, Date dateNaissance, String telephone, String email) {
this.idCollaborateur = idCollaborateur;
this.cin = cin;
this.nom = nom;
this.prenom = prenom;
this.dateNaissance = dateNaissance;
this.telephone = telephone;
this.email = email;
}
#Id
#Column(name = "id_collaborateur", unique = true, nullable = false)
public int getIdCollaborateur() {
return this.idCollaborateur;
}
public void setIdCollaborateur(int idCollaborateur) {
this.idCollaborateur = idCollaborateur;
}
#Column(name = "cin", nullable = false, length = 254)
public String getCin() {
return this.cin;
}
public void setCin(String cin) {
this.cin = cin;
}
#Column(name = "nom", length = 254)
public String getNom() {
return this.nom;
}
public void setNom(String nom) {
this.nom = nom;
}
#Column(name = "prenom", length = 254)
public String getPrenom() {
return this.prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "dateNaissance", length = 19)
public Date getDateNaissance() {
return this.dateNaissance;
}
public void setDateNaissance(Date dateNaissance) {
this.dateNaissance = dateNaissance;
}
#Column(name = "telephone", length = 254)
public String getTelephone() {
return this.telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
#Column(name = "email", length = 254)
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
}
edit
This is what i get when i debug collaborateur.xhtml on the console. I'm using jboss 7
17:10:44,419 INFOS [org.jboss.modules] JBoss Modules version 1.1.1.GA
17:10:44,622 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA
17:10:44,684 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
17:10:45,589 INFO [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
17:10:45,589 INFO [org.xnio] XNIO Version 3.0.3.GA
17:10:45,604 INFO [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
17:10:45,604 INFO [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
17:10:45,640 INFO [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
17:10:45,642 INFO [org.jboss.as.configadmin] (ServerService Thread Pool -- 26) JBAS016200: Activating ConfigAdmin Subsystem
17:10:45,704 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem
17:10:45,720 INFO [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
17:10:45,735 INFO [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem
17:10:45,735 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
17:10:45,735 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
17:10:45,735 INFO [org.jboss.as.connector] (MSC service thread 1-2) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
17:10:45,751 INFO [org.jboss.as.naming] (MSC service thread 1-1) JBAS011802: Starting Naming Service
17:10:45,751 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
17:10:45,782 INFO [org.jboss.as.security] (MSC service thread 1-6) JBAS013100: Current PicketBox version=4.0.7.Final
17:10:45,798 INFO [org.jboss.as.mail.extension] (MSC service thread 1-5) JBAS015400: Bound mail session [java:jboss/mail/Default]
17:10:46,078 INFO [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-5) JBoss Web Services - Stack CXF Server 4.0.2.GA
17:10:46,145 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-6) Démarrage de Coyote HTTP/1.1 sur http-localhost-127.0.0.1-8080
17:10:46,566 INFO [org.jboss.as.remoting] (MSC service thread 1-3) JBAS017100: Listening on localhost/127.0.0.1:9999
17:10:46,566 INFO [org.jboss.as.remoting] (MSC service thread 1-5) JBAS017100: Listening on localhost/127.0.0.1:4447
17:10:46,582 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-4) JBAS015012: Started FileSystemDeploymentService for directory C:\Program Files\jboss-as-7.1.1.Final\standalone\deployments
17:10:46,661 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found MyPro.war in deployment directory. To trigger deployment create a file called MyPro.war.dodeploy
17:10:46,661 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found Projet.war in deployment directory. To trigger deployment create a file called Projet.war.dodeploy
17:10:46,661 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found Projet_sqli.war in deployment directory. To trigger deployment create a file called Projet_sqli.war.dodeploy
17:10:46,739 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
17:10:46,754 INFO [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015876: Starting deployment of "MyPro.war"
17:10:46,754 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015876: Starting deployment of "Projet_sqli.war"
17:10:47,430 INFO [org.jboss.web] (MSC service thread 1-4) JBAS018210: Registering web context: /MyPro
17:10:48,853 WARN [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015893: Encountered invalid class name 'com.sun.faces.vendor.Tomcat6InjectionProvider:org.apache.catalina.util.DefaultAnnotationProcessor' for service type 'com.sun.faces.spi.injectionprovider'
17:10:48,853 WARN [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015893: Encountered invalid class name 'com.sun.faces.vendor.Jetty6InjectionProvider:org.mortbay.jetty.plus.annotation.InjectionCollection' for service type 'com.sun.faces.spi.injectionprovider'
17:10:49,260 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
17:10:49,260 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)
17:10:49,275 INFO [org.apache.catalina.core.StandardContext] (MSC service thread 1-1) The listener "com.sun.faces.config.ConfigureListener" is already configured for this context. The duplicate definition has been ignored.
17:10:49,306 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/Projet_sqli]] (MSC service thread 1-1) Initializing Spring root WebApplicationContext
17:10:49,306 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-1) Root WebApplicationContext: initialization started
17:10:49,322 INFO [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-1) Refreshing org.springframework.web.context.support.XmlWebApplicationContext#ccce74: display name [Root WebApplicationContext]; startup date [Wed Dec 03 17:10:49 WET 2014]; root of context hierarchy
17:10:49,353 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-1) Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
17:10:49,696 INFO [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-1) Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext#ccce74]: org.springframework.beans.factory.support.DefaultListableBeanFactory#7095b
17:10:49,759 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-1) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#7095b: defining beans [org.springframework.beans.factory.config.CustomScopeConfigurer#0,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor]; root of factory hierarchy
17:10:49,759 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-1) Root WebApplicationContext: initialization completed in 453 ms
17:10:49,774 INFOS [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-1) Initialisation de Mojarra 2.1.7-jbossorg-1 (20120227-1401) pour le contexte «/Projet_sqli»
17:10:50,696 INFO [org.hibernate.validator.util.Version] (MSC service thread 1-1) Hibernate Validator 4.2.0.Final
17:10:51,477 INFOS [org.primefaces.webapp.PostConstructApplicationEventListener] (MSC service thread 1-1) Running on PrimeFaces 5.1
17:10:51,492 INFOS [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-1) Monitoring jndi:/default-host/Projet_sqli/WEB-INF/faces-config.xml for modifications
17:10:51,508 INFO [org.jboss.web] (MSC service thread 1-1) JBAS018210: Registering web context: /Projet_sqli
17:10:51,508 INFO [org.jboss.as] (MSC service thread 1-4) JBAS015951: Admin console listening on http://127.0.0.1:9990
17:10:51,508 INFO [org.jboss.as] (MSC service thread 1-4) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 7401ms - Started 319 of 398 services (78 services are passive or on-demand)
17:10:51,539 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "Projet_sqli.war"
17:10:51,539 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "MyPro.war"
i found a solution for this problem. I had missing dependencies and i had to delete some dependencies because of problems in versions
this is my new 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>ma.ensa</groupId>
<artifactId>Projet_sqli</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Projet_sqli Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.7.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.8-02</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.8-02</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<build>
<finalName>Projet_sqli</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

Spring JSF Integration pure Java Config (No web.xml)

I'm trying to integrate Spring 4 and JSF 2.x using java config. I am trying to modify the source from the following project to accomplish this.
https://github.com/spring-projects/spring-webflow-samples/tree/master/booking-faces
However, I am stuck can anyone help me. From what I understand I need a FacesServlet but how do i configure that using java config.
pom.xml (Not yet perfect still trying to figure out what I need)
<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>Test</groupId>
<artifactId>TestId</artifactId>
<packaging>war</packaging>
<version>1</version>
<name>TestId Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>4.0.5.RELEASE</spring.version>
<spring.security.version>3.2.4.RELEASE</spring.security.version>
<jstl.version>1.2</jstl.version>
<webflow-version>2.3.3.RELEASE</webflow-version>
<mojarra-version>2.2.5</mojarra-version>
</properties>
<repositories>
<repository>
<id>prime-repo</id>
<name>Prime Repo</name>
<url>http://repository.primefaces.org</url>
</repository>
</repositories>
<dependencies>
<!-- Spring 4 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring webflow -->
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-faces</artifactId>
<version>${webflow-version}</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- jstl for jsp page -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<!-- jsf -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${mojarra-version}</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${mojarra-version}</version>
</dependency>
<!-- primefaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>
<!-- slf4j logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.7</version>
</dependency>
<!-- logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
<finalName>TestId</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
AppConfig.java
package org.bdo.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
#Configuration
#ComponentScan(basePackages = "org.bdo")
#Import(value = { WebMvcConfig.class })
public class AppConfig
{
}
WebMvcConfig.java
package org.bdo.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.faces.mvc.JsfView;
import org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
#Configuration
public class WebMvcConfig {
#Bean
public UrlBasedViewResolver faceletsViewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setViewClass(JsfView.class);
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix(".xhtml");
return resolver;
}
#Bean
public SimpleControllerHandlerAdapter simpleControllerHandlerAdapter() {
return new SimpleControllerHandlerAdapter();
}
}
DispatcherServletInitializer.java
package org.config;
import javax.servlet.Filter;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import com.sun.faces.config.ConfigureListener;
public class DispatcherServletInitializer extends
AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { AppConfig.class };
}
#Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
#Override
protected String[] getServletMappings() {
return new String[] { "/spring/*" };
}
#Override
protected Filter[] getServletFilters() {
return new Filter[] { new CharacterEncodingFilter() };
}
#Override
public void onStartup(ServletContext servletContext)
throws ServletException {
// Use JSF view templates saved as *.xhtml, for use with Facelets
servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml");
// Enable special Facelets debug output during development
servletContext.setInitParameter("javax.faces.PROJECT_STAGE",
"Development");
// Causes Facelets to refresh templates during development
servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD",
"1");
// Declare Spring Security Facelets tag library
servletContext.setInitParameter("javax.faces.FACELETS_LIBRARIES",
"/WEB-INF/springsecurity.taglib.xml");
servletContext.addListener(ConfigureListener.class);
// Let the DispatcherServlet be registered
super.onStartup(servletContext);
}
}
intro.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<p:spinner />
</h:body>
</html>
Partial Stack Trace
21:38:51.479 [localhost-startStop-1] DEBUG o.springframework.jndi.JndiTemplate - Looking up JNDI object with name [spring.liveBeansView.mbeanDomain]
21:38:51.479 [localhost-startStop-1] DEBUG o.s.jndi.JndiPropertySource - JNDI lookup for name [spring.liveBeansView.mbeanDomain] threw NamingException with message: Name [spring.liveBeansView.mbeanDomain] is not bound in this Context. Unable to find [spring.liveBeansView.mbeanDomain].. Returning null.
21:38:51.479 [localhost-startStop-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemProperties]
21:38:51.479 [localhost-startStop-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
21:38:51.479 [localhost-startStop-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [null]
21:38:51.479 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Published WebApplicationContext of servlet 'dispatcher' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher]
21:38:51.479 [localhost-startStop-1] INFO o.s.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcher': initialization completed in 189 ms
21:38:51.479 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Servlet 'dispatcher' configured successfully
May 27, 2014 9:38:51 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\Admin\Desktop\New Folder (4)\sts-bundle\vfabric-tc-server-developer-2.9.5.SR1\base-instance\webapps\manager
May 27, 2014 9:38:51 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\Admin\Desktop\New Folder (4)\sts-bundle\vfabric-tc-server-developer-2.9.5.SR1\base-instance\webapps\ROOT
May 27, 2014 9:38:51 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
May 27, 2014 9:38:51 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3271 ms
21:38:53.156 [tomcat-http--4] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/SpringJSF/spring/intro]
21:38:53.157 [tomcat-http--4] WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/SpringJSF/spring/intro] in DispatcherServlet with name 'dispatcher'
21:38:53.157 [tomcat-http--4] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
May 27, 2014 9:39:06 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
May 27, 2014 9:39:06 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
May 27, 2014 9:39:07 PM org.apache.catalina.core.ApplicationContext log
INFO: Destroying Spring FrameworkServlet 'dispatcher'
21:39:07.403 [localhost-startStop-2] INFO o.s.w.c.s.AnnotationConfigWebApplicationContext - Closing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Tue May 27 21:38:51 CST 2014]; parent: Root WebApplicationContext
May 27, 2014 9:39:07 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
21:39:07.403 [localhost-startStop-2] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
21:39:07.403 [localhost-startStop-2] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#8d8962: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#3c718
21:39:07.403 [localhost-startStop-2] INFO o.s.w.c.s.AnnotationConfigWebApplicationContext - Closing Root WebApplicationContext: startup date [Tue May 27 21:38:50 CST 2014]; root of context hierarchy
21:39:07.403 [localhost-startStop-2] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
21:39:07.403 [localhost-startStop-2] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#3c718: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,appConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor,webMvcConfig,faceletsViewResolver,simpleControllerHandlerAdapter]; root of factory hierarchy
21:39:07.403 [localhost-startStop-2] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy() on bean with name 'webMvcConfig'
21:39:07.403 [localhost-startStop-2] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy() on bean with name 'appConfig'
May 27, 2014 9:39:07 PM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8080"]
in your servlet initializer, use this:
/** Faces Servlet */
ServletRegistration.Dynamic facesServlet = servletContext.addServlet("Faces Servlet", FacesServlet.class);
facesServlet.setLoadOnStartup(1);
facesServlet.addMapping("*.xhtml");

Resources