The example below assumes that you have already defined a DataSource within your application.
use @Configuration class that provides a datasource through @Bean
You assigned the Datasource an ID value of "Datasource". That violates the convention that object instance names should begin with a lower-case letter. It therefore defeats Spring's auto-wiring because auto-wiring defaults to looking for the class name folded to an initial lowercase per the convention.
To inject a Datasource directly into JSF code, configure the Spring-JSF bridge into faces-config.xml and inject it as a ManagedProperty (not Autowired). But I don't recommend that. I recommend backing off a layer and making a separate (Spring) bean to hold the persistence functions and autowired Datasource, then injecting THAT bean as a ManagedProperty into the JSF Managed Bean.
Tim Holloway wrote:Mostly I find the JEE standard container security sufficient, so I only have 1 or 2 apps that use Spring security and thus I'm not up to date on all its ins and outs. But I think I can suggest a couple of things.
Tim Holloway wrote:
Firstly, a DataSource is usually injected externally into webapps, not configured as part of the webapp itself. In Tomcat, for example, you'd define a database Connection Pool either in the app's Context definition (server-specific deployment descriptor) or - if the pool is intended to be shared between multiple webapps, by defining it in Tomcat's server.xml config file. Servers such as IBM WebSphere or Oracle WebLogic provide an admin GUI function for that, JBoss/Wildfly has its own special config files.
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton