I HomeController a UserService Wired becomes object that spring used correctly (it renders index page just a method UserService Using) Now I setup Hibernate, then inside the UserService I have a userDao object that I am trying to wire using spring. } So was my Homkantrolr 'Halo' calling the method and I was right that it was working properly. userService.getTestUser (call to), as fails UserDao blank My App config. Xml is: Why is my UserDao empty? Should I mess with the stars? In addition, if I exclude the name = packagesToScan line, do I really need to define Bean for each claim as I did with Userdao? Will the sessionFactory be wired anyhow?
@Service public class UserServiceImpl applies UserService {userDao userDao; Public string is like hello () {"Hello Part 2" from participating in the "User Service"; } Public string getTestUser () {return user Dao.getById (1L) .getUsername (); }
@ Controller Public Class Home Controller {@Autowired Private User Service Service; @RequestMapping ("/") Public Model and Visual Index () {ModelAndView mav = New ModelAndView (); Mav.setViewName ("index"); Mav.addObject ("Message", userService.sayHello ()); Mav.addObject ("user name", userService.getTestUser ()); //userService.getTestUser (); Return mawa; }
& lt ;! - Hibernation session factory - & gt; & Lt; Bean id = "sessionFactory" class = "org.springframework.orm.hibernate3.annotation.nnationationSessionFactoryBean" & gt; & Lt; Property Name = "Data Source" Riff = "Data Sources" / & gt; & Lt ;! - & lt; Property Name = "packagesToScan" value = "com.blah.core.db.hibernate" /> - & gt; & Lt; Property Name = "Configuration Location" value = "/ Web-NF / Class / Hibernate Cfg.xml" /> & Lt; Property Name = "Hibernate Properties" & gt; & Lt; Price & gt; hibernate.dialect = org.hibernate.dialect.MySQLDialect hibernate.connection.url = JDBC: mysql: // localhost / blah hibernate.connection.username = dbuser hibernate.connection.password = 123 hibernate.query.substitutions = true 'Y 'false' n 'hibernate.cache.use_query_cache = true hibernate.cache.use_second_level_cache = true hibernate.cache.provider_class = org.hibernate.cache.EhCacheProvider hibernate.jdbc.batch_size = 0 & lt; / Pricing & gt; & Lt; / Property & gt; & Lt; / Bean & gt; & Lt ;! - transaction manager for a single hibernate session factory (JTA option) - & gt; & Lt; Bean id = "Userdao" class = "com.blah.core.db.hibernate.UserDaoImpl" & gt; & Lt; Property Name = "sessionFactory" ref = "SessionFire" / & gt; & Lt; / Bean & gt;
Add @AutoWired annotations userDao.
@Service Public Class UserServiceImpl User Service {@ Autoward UserDo Usager applies; ...} and make sure that you @Service to scan packages s and & lt; Context: component-scan / & gt; is set up @Controller s are inside.
Comments
Post a Comment