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
- Tomcat 10.x with boss weld (weld-servlet-shaded 5.0.0) to support CDI
- JSF (jakarta.faces from glass fish 4.0.0)
- 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
- Do i need spring web here ? as I have JSF i do not want to make it complex using spring web.
- Do i Need Jboss weld here? or tomcat 10 support CDI 2.0 should i skip?
- I want all spring beans to be initialised on tomcat start and ready for all request via JSF.