Vandan Hatkar
Vandan Hatkar

Reputation: 11

JSF 2.3 CDI with spring beans

JSF 2.3, CDI, Tomcat 10, Spring bean. I would like to use the latest JSF 2.3 capabilities from Jakarta with spring jdbc. Since JSF is now part of Jakarta and covered under CDI I am struggling how to initialise spring beans and connect it with JSF. My environment is

  1. Tomcat 10.x with boss weld (weld-servlet-shaded 5.0.0) to support CDI
  2. JSF (jakarta.faces from glass fish 4.0.0)
  3. Spring core, context and jdbc (6.0.2), I am not using spring-web (i do not want to use as i have jsf as my web) and no spring boot.

**I have my jsf bean as below **

@Named
@RequestScoped
public class UserProfile {

    @Inject
    private UserService userService;

    public String getMessage() {
        return userService.getMessage();
    }
}

Spring service as

@Service
public class UserService {

    @Inject
    private UserDao userDao;

    public String getMessage() {
        return userDao.getMessage();
    }
}

**And Dao as **

@Repository
public class UserDao  extends JdbcDaoSupport{
    
    @Autowired
    private DataSource dataSource;
    
    
    @PostConstruct
    public void init() {
        setDataSource(dataSource);
    }
    
    public String getMessage(){
        Integer empCount =  getJdbcTemplate().queryForObject("SELECT COUNT(*) FROM EMPLOYEE", Integer.class) ;
        return empCount.toString();
    }
}

Datasource, Hikari configuration and jdbcTemplate is defined under applicationContext.xml Unfortunately I am not getting my datasource initialised..

Any clue?

I have tried the traditional way of jsf spring integration but it did not work, my question is

  1. Do i need spring web here ? as I have JSF i do not want to make it complex using spring web.
  2. Do i Need Jboss weld here? or tomcat 10 support CDI 2.0 should i skip?
  3. I want all spring beans to be initialised on tomcat start and ready for all request via JSF.

Upvotes: 1

Views: 600

Answers (0)

Related Questions