<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/library" /> <property name="username" value="root" /> <property name="password" value="password" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan" value="com.example.library.models" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> </beans> package com.example.library.models; public class Book { private int id; private String title; private String author; } package com.example.library.services; public class BookService { private BookRepository bookRepository; public BookService(BookRepository bookRepository) { this.bookRepository = bookRepository; } } package com.example.library.controllers; public class BookController { private BookService bookService; public BookController(BookService bookService) { this.bookService = bookService; } }


上一篇:
下一篇:
切换中文