jsf-spring-integration - moving to java config
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.springintegration.config;
|
||||
|
||||
import com.sun.faces.config.FacesInitializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.WebApplicationInitializer;
|
||||
import org.springframework.web.context.ContextLoaderListener;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import java.util.Set;
|
||||
|
||||
public class MainWebAppInitializer extends FacesInitializer implements WebApplicationInitializer {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MainWebAppInitializer.class);
|
||||
|
||||
@Override
|
||||
public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException {
|
||||
super.onStartup(classes, servletContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and configure all Servlet container components necessary to power the web application.
|
||||
*/
|
||||
@Override
|
||||
public void onStartup(final ServletContext sc) throws ServletException {
|
||||
LOGGER.info("MainWebAppInitializer.onStartup()");
|
||||
sc.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", "true");
|
||||
|
||||
// Create the 'root' Spring application context
|
||||
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
|
||||
root.register(SpringCoreConfig.class);
|
||||
sc.addListener(new ContextLoaderListener(root));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.springintegration.config;
|
||||
|
||||
import com.baeldung.springintegration.dao.UserManagementDAO;
|
||||
import com.baeldung.springintegration.dao.UserManagementDAOImpl;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class SpringCoreConfig {
|
||||
|
||||
@Bean
|
||||
public UserManagementDAO userManagementDAO() {
|
||||
return new UserManagementDAOImpl();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.baeldung.springintegration.controllers;
|
||||
|
||||
import com.baeldung.springintegration.dao.IUserManagementDAO;
|
||||
import com.baeldung.springintegration.dao.UserManagementDAO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -16,7 +16,7 @@ public class RegistrationBean implements Serializable {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationBean.class);
|
||||
|
||||
@ManagedProperty(value = "#{userManagementDAO}")
|
||||
transient private IUserManagementDAO userDao;
|
||||
transient private UserManagementDAO userDao;
|
||||
private String userName;
|
||||
private String operationMessage;
|
||||
|
||||
@@ -44,11 +44,11 @@ public class RegistrationBean implements Serializable {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public void setUserDao(IUserManagementDAO userDao) {
|
||||
public void setUserDao(UserManagementDAO userDao) {
|
||||
this.userDao = userDao;
|
||||
}
|
||||
|
||||
public IUserManagementDAO getUserDao() {
|
||||
public UserManagementDAO getUserDao() {
|
||||
return this.userDao;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.springintegration.dao;
|
||||
|
||||
|
||||
/**
|
||||
* @author Tayo
|
||||
*/
|
||||
public abstract class IUserManagementDAO implements UserManagementDAO {
|
||||
|
||||
|
||||
@Override
|
||||
public abstract boolean createUser(String userName);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,16 +1,7 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.springintegration.dao;
|
||||
|
||||
|
||||
/**
|
||||
* @author Tayo
|
||||
*/
|
||||
public interface UserManagementDAO {
|
||||
|
||||
public boolean createUser(String newUserData);
|
||||
|
||||
boolean createUser(String newUserData);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.baeldung.springintegration.dao;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
public class UserManagementDAOImpl extends IUserManagementDAO {
|
||||
@Repository
|
||||
public class UserManagementDAOImpl implements UserManagementDAO {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UserManagementDAOImpl.class);
|
||||
|
||||
private List<String> users;
|
||||
|
||||
@@ -19,7 +24,7 @@ public class UserManagementDAOImpl extends IUserManagementDAO {
|
||||
public boolean createUser(String newUserData) {
|
||||
if (newUserData != null) {
|
||||
users.add(newUserData);
|
||||
Logger.getAnonymousLogger().log(Level.INFO, "User {0} successfully created", newUserData);
|
||||
LOGGER.info("User {} successfully created", newUserData);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user