my userService is null how do to fixe ? tnks ;)
java.lang.NullPointerException
at com.what.now.rest.RestCreateUser.cretaeAccount(RestCreateUser.java:52)
REST Service
service for browser
package com.what.now.rest;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.what.now.business.IUserBusiness;
import com.what.now.model.bean.User;
import com.what.now.model.dto.AccountRegisterDTO;
import com.what.now.tools.ConverterUserBeanDTO;
import com.what.now.tools.ValidateRestInput;
/**
* Rest Service
*
*/
@Component
@Path("/register")
public class RestCreateUser {
@Autowired
private IUserBusiness userService;
@POST
@Path("/createAccount")
@Produces({ MediaType.APPLICATION_JSON, })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XHTML_XML })
public Boolean cretaeAccount(final AccountRegisterDTO newAccount) {
Boolean result = false;
// create user
User user = ConverterUserBeanDTO.userDtoToBean(newAccount);
// add dto in bean
// save user
userService.create(user);
// result to save
if (user.getId() != 0) {
result = true;
}
return result;
}
Service
service to add in data base
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.what.now.business.IUserBusiness;
import com.what.now.dao.IUserDAO;
import com.what.now.model.bean.User;
@Service
public class UserBusinessImpl implements IUserBusiness {
@Autowired
IUserDAO userDAO;
public void create(User user) {
userDAO.create(user);
}
public User find(String id) {
return userDAO.find(id);
}
public void update(User user) {
userDAO.update(user);
}
public void delete(User user) {
userDAO.delete(user);
}
}
web.xml
conf for web app .. this conf to load spring context and init Jersey servlet
<web-app xmlns="http://ift.tt/nSRXKP" xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/nSRXKP
http://ift.tt/1eWqHMP"
version="3.0">
// context application
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:*/applicationContext.xml </param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>whatNow-rest-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.what.now.rest</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>whatNow-rest-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
applicationContext.xml
this my application configuration
<context:component-scan base-package="com.what.now.*"
annotation-config="true" />
<tx:annotation-driven/>
</beans>
pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://ift.tt/IH78KX http://ift.tt/VE5zRx" xmlns="http://ift.tt/IH78KX"
xmlns:xsi="http://ift.tt/ra1lAU">
<modelVersion>4.0.0</modelVersion>
<groupId>com.what.now.project</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>whatNow-packaging</artifactId>
<packaging>war</packaging>
<url>http://ift.tt/19pvvEY;
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.8</jdk.version>
<spring.version>3.2.13.RELEASE</spring.version>
<jersey.version>1.17.1</jersey.version>
<jersey.client.version>1.17.1</jersey.client.version>
<jersey.servlet.version>1.17.1</jersey.servlet.version>
<jersey.json.version>1.17.1</jersey.json.version>
<jersey.multipart>1.17.1</jersey.multipart>
<javax.mail>1.4</javax.mail>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</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-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Jersey -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.json.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>${jersey.servlet.version}</version>
</dependency>
<!-- Spring + Jersey -->
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- hibernate -->
</dependencies>
</build>
</project>
Aucun commentaire:
Enregistrer un commentaire