...................
Я пробую Spring Framework с гибернацией, но застрял на ошибках. Я пробую все решения в stackoverflow, но оно не работает.
..................
org.springframework.beans .factory.UnsatisfiedDependencyException: Ошибка создания компонента с именем 'musteriController':
Неудовлетворенная зависимость, выраженная через поле 'musteriServis'; вложенное исключение: org.springframework.beans.factory.UnsatisfiedDependencyException: ошибка создания бина с именем 'musteriServis':
Неудовлетворенная зависимость, выраженная через поле 'musteriDao'; вложенное исключение - org.springframework.beans.factory.UnsatisfiedDependencyException: ошибка создания бина с именем 'musteriDao':
Неудовлетворенная зависимость, выраженная через поле 'sessionFactory'; вложенным исключением является org.springframework.beans.factory.BeanCreationException: ошибка создания бина с именем 'sessionFactoryBean', определенным в ресурсе ServletContext [/WEB-INF/spring/appServlet/servlet-context.xml]:
Вызов сбой метода init; вложенное исключение: java .lang.NoSuchMethodError: org.hibernate.cfg.annotations.reflection.JPAMetadataProvider. (Lorg / hibernate / boot / spi / BootstrapContext;)
Мой интерфейс Дао 1019 *
public interface MusteriDao {
List<Musteri> musteriler();
List<Musteri> musteriAraAd(String adi);
}
Мой класс Дао
@SuppressWarnings({ "deprecation", "unchecked" })
@Repository("musteriDao")
public class MusteriDaoImpl implements MusteriDao,Serializable{
private static final long serialVersionUID = 1L;
@Autowired
private SessionFactory sessionFactory;
@Override
public List<Musteri> musteriler() {
try {
return sessionFactory.getCurrentSession().createQuery("from Musteri").getResultList();
} catch (Exception e) {
System.out.println("Müsteriler Listelenemedi..." + e);
return null;
}
}
@Override
public List<Musteri> musteriAraAd(String adi) {
try {
Session session=sessionFactory.openSession();
Query<Musteri> query=session.createQuery("from Musteri where musteriAdi=_musteriAdi");
query.setParameter("_musteriAdi", adi);
List<Musteri> musteri=query.getResultList();
return musteri;
} catch (Exception e) {
System.out.println("Müsteriler Listelenemedi..." + e);
return null;
}
}
}
Интерфейс обслуживания
public interface MusteriServis {
List<Musteri> musteriler();
List<Musteri> musteriAraAd(String adi);
}
Класс ServisImpl
@Service("musteriServis")
@Transactional
public class MusteriServisImpl implements MusteriServis{
@Autowired
MusteriDao musteriDao;
@Override
public List<Musteri> musteriler() {
return musteriDao.musteriler();
}
@Override
public List<Musteri> musteriAraAd(String adi) {
return musteriDao.musteriAraAd(adi);
}
}
Класс контроллера
@Controller
public class MusteriController {
@Autowired
private MusteriServis musteriServis;
@RequestMapping("giris")
public ModelAndView giris(@ModelAttribute Musteri musteri) {
ModelAndView modelAndView=new ModelAndView("musteriForm");
return modelAndView;
}
@RequestMapping(value = "musteriler",method = RequestMethod.GET)
public ModelAndView musteriler() {
List<Musteri> musteriler=musteriServis.musteriler();
return new ModelAndView("musteriList","musteriler",musteriler);
}
@RequestMapping(value = "musteriAd",method = RequestMethod.GET)
public ModelAndView musteriAd(@RequestParam String adi) {
List<Musteri> musteriler=musteriServis.musteriAraAd(adi);
return new ModelAndView("musteriList","musteriler",musteriler);
}
}
Servlet-Context
<annotation-driven />
<context:component-scan base-package="com.umitcelebi" />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:property-placeholder location="classpath:application.properties" />
<beans:bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<beans:property name="user" value="${database.username}"></beans:property>
<beans:property name="password" value="${database.password}"></beans:property>
<beans:property name="driverClass" value="${database.driverClass}"></beans:property>
<beans:property name="jdbcUrl" value="${database.url}"></beans:property>
</beans:bean>
<beans:bean id="sessionFactoryBean"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource"></beans:property>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">${hibernate.dialect}</beans:prop>
<beans:prop key="hibernate.show_sql">$hibernate.show_sql}</beans:prop>
<beans:prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</beans:prop>
</beans:props>
</beans:property>
<beans:property name="packagesToScan" value="com.umitcelebi.model"></beans:property>
</beans:bean>
<beans:bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactoryBean"></beans:property>
</beans:bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
web . xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
пом. xml
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-expression -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${org.hibernate-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${org.hibernate-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${org.hibernate-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${org.hibernate-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-tools -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>${org.hibernate-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-java8 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>${org.hibernate-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.5.4-Final</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-annotations -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.4-Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.17.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>