Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:jee="http://www.springframework.org/schema/jee"
- xmlns:lang="http://www.springframework.org/schema/lang"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
- ">
- <bean id="transactionManager"
- class="org.springframework.orm.hibernate5.HibernateTransactionManager">
- <property name="sessionFactory" ref="sessionFactory"/>
- </bean>
- <bean id="sessionFactory"
- class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="configLocation">
- <value>classpath:hibernate.cfg.xml</value>
- </property>
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.show_sql">true</prop>
- <prop key="hibernate.dialect">${jdbc.dialect}</prop>
- <prop key="hibernate.connection.charSet">UTF-8</prop>
- </props>
- </property>
- </bean>
- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
- p:driverClassName="${jdbc.driverClassName}"
- p:url="${jdbc.databaseUrl}"
- p:username="${jdbc.username}"
- p:password="${jdbc.password}"/>
- <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
- p:location="/WEB-INF/jdbc.properties"/>
- <bean id="messageSource"
- class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
- <property name="basename" value="messages"/>
- <property name="defaultEncoding" value="UTF-8"/>
- </bean>
- <tx:annotation-driven transaction-manager="transactionManager"/>
- </beans>
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:jee="http://www.springframework.org/schema/jee"
- xmlns:lang="http://www.springframework.org/schema/lang"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
- http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
- >
- <context:annotation-config/>
- <context:component-scan base-package="com"/>
- <import resource="data.xml"/>
- </beans>
- <?xml version="1.0" encoding="UTF-8" ?>
- <web-app
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/root-context.xml</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <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/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>
- <!-- Encoder -->
- <filter>
- <filter-name>charsetFilter</filter-name>
- <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- <init-param>
- <param-name>forceEncoding</param-name>
- <param-value>true</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>charsetFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- </web-app>
- jdbc.driverClassName= org.postgresql.Driver
- jdbc.dialect=org.hibernate.dialect.PostgreSQLDialect
- jdbc.databaseurl=jdbc:postgresql://localhost:5432/shopbase
- jdbc.username=user
- jdbc.password=1234
- <?xml version='1.0' encoding='utf-8'?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <mapping class="com.model.Product" />
- </session-factory>
- </hibernate-configuration>
- import javax.persistence.*;
- @Entity
- @Table(name = "product")
- public class Product {
- @Id
- @Column(name = "id")
- @GeneratedValue
- private int id;
- @Column(name = "name")
- private String name;
- @Column(name = "price")
- private float price;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public float getPrice() {
- return price;
- }
- public void setPrice(float price) {
- this.price = price;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement