From fdfb24d960ea252b96cff6b213fe3e492413cf2a Mon Sep 17 00:00:00 2001 From: eugenp Date: Sat, 11 May 2013 17:04:57 +0300 Subject: [PATCH] mvc work to replicate the error --- spring-beandefinitionstoreexception/pom.xml | 22 +----- .../config/HibernateXmlConfig.java | 18 ----- .../persistence/config/PersistenceConfig.java | 79 ------------------- .../spring/persistence/dao/FooDao.java | 14 ---- .../spring/persistence/dao/IFooDao.java | 5 -- .../spring/persistence/model/Foo.java | 31 -------- .../persistence/service/FooService.java | 19 ----- .../spring/web/config/ClientWebConfig.java | 39 +++++++++ .../src/main/resources/hibernate4Config.xml | 35 -------- .../resources/persistence-mysql.properties | 10 --- .../src/main/webapp/WEB-INF/web.xml | 55 +++++++++---- 11 files changed, 81 insertions(+), 246 deletions(-) delete mode 100644 spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/config/HibernateXmlConfig.java delete mode 100644 spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/config/PersistenceConfig.java delete mode 100644 spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/dao/FooDao.java delete mode 100644 spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/dao/IFooDao.java delete mode 100644 spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/model/Foo.java delete mode 100644 spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/service/FooService.java create mode 100644 spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/web/config/ClientWebConfig.java delete mode 100644 spring-beandefinitionstoreexception/src/main/resources/hibernate4Config.xml delete mode 100644 spring-beandefinitionstoreexception/src/main/resources/persistence-mysql.properties diff --git a/spring-beandefinitionstoreexception/pom.xml b/spring-beandefinitionstoreexception/pom.xml index 02cd5f48c9..b5f593a1f1 100644 --- a/spring-beandefinitionstoreexception/pom.xml +++ b/spring-beandefinitionstoreexception/pom.xml @@ -18,34 +18,16 @@ org.springframework - spring-orm + spring-webmvc ${org.springframework.version} + org.springframework spring-context ${org.springframework.version} - - - - org.hibernate - hibernate-core - 4.2.1.Final - - - org.javassist - javassist - 3.17.1-GA - - - mysql - mysql-connector-java - 5.1.25 - runtime - - diff --git a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/config/HibernateXmlConfig.java b/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/config/HibernateXmlConfig.java deleted file mode 100644 index 51fbcd27c1..0000000000 --- a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/config/HibernateXmlConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.baeldung.spring.persistence.config; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -@Configuration -@EnableTransactionManagement -@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" }) -@ImportResource({ "classpath:hibernate4Config.xml" }) -public class HibernateXmlConfig { - - public HibernateXmlConfig() { - super(); - } - -} \ No newline at end of file diff --git a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/config/PersistenceConfig.java b/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/config/PersistenceConfig.java deleted file mode 100644 index 3157c92e99..0000000000 --- a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/config/PersistenceConfig.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.baeldung.spring.persistence.config; - -import java.util.Properties; - -import javax.sql.DataSource; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.orm.hibernate4.HibernateTransactionManager; -import org.springframework.orm.hibernate4.LocalSessionFactoryBean; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import com.google.common.base.Preconditions; - -@Configuration -@EnableTransactionManagement -@PropertySource({ "classpath:persistence-mysql.properties" }) -@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" }) -public class PersistenceConfig { - - @Autowired - private Environment env; - - public PersistenceConfig() { - super(); - } - - @Bean - public LocalSessionFactoryBean sessionFactory() { - final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); - sessionFactory.setDataSource(restDataSource()); - sessionFactory.setPackagesToScan(new String[] { "org.baeldung.spring.persistence.model" }); - sessionFactory.setHibernateProperties(hibernateProperties()); - - return sessionFactory; - } - - @Bean - public DataSource restDataSource() { - final DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); - dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); - dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); - dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); - - return dataSource; - } - - @Bean - public HibernateTransactionManager transactionManager() { - final HibernateTransactionManager txManager = new HibernateTransactionManager(); - txManager.setSessionFactory(sessionFactory().getObject()); - - return txManager; - } - - @Bean - public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { - return new PersistenceExceptionTranslationPostProcessor(); - } - - final Properties hibernateProperties() { - return new Properties() { - { - setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); - setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); - - // setProperty("hibernate.globally_quoted_identifiers", "true"); - // note: necessary in launchpad-storage, but causing problems here - } - }; - } -} \ No newline at end of file diff --git a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/dao/FooDao.java b/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/dao/FooDao.java deleted file mode 100644 index a59bb30f48..0000000000 --- a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/dao/FooDao.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.baeldung.spring.persistence.dao; - -import org.springframework.stereotype.Repository; - -@Repository -public class FooDao implements IFooDao { - - public FooDao() { - super(); - } - - // API - -} diff --git a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/dao/IFooDao.java b/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/dao/IFooDao.java deleted file mode 100644 index 91d44f5f6b..0000000000 --- a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/dao/IFooDao.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.baeldung.spring.persistence.dao; - -public interface IFooDao { - // -} diff --git a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/model/Foo.java b/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/model/Foo.java deleted file mode 100644 index 8842c26d95..0000000000 --- a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/model/Foo.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.baeldung.spring.persistence.model; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -public class Foo { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private long id; - - public Foo() { - super(); - } - - // API - - public long getId() { - return id; - } - - public void setId(final long id) { - this.id = id; - } - - // - -} diff --git a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/service/FooService.java b/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/service/FooService.java deleted file mode 100644 index cda31a0e86..0000000000 --- a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/persistence/service/FooService.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.baeldung.spring.persistence.service; - -import org.baeldung.spring.persistence.dao.IFooDao; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class FooService { - - @Autowired - private IFooDao fooDao; - - public FooService() { - super(); - } - - // API - -} diff --git a/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/web/config/ClientWebConfig.java b/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/web/config/ClientWebConfig.java new file mode 100644 index 0000000000..2758a707e6 --- /dev/null +++ b/spring-beandefinitionstoreexception/src/main/java/org/baeldung/spring/web/config/ClientWebConfig.java @@ -0,0 +1,39 @@ +package org.baeldung.spring.web.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.view.InternalResourceViewResolver; +import org.springframework.web.servlet.view.JstlView; + +@EnableWebMvc +@Configuration +public class ClientWebConfig extends WebMvcConfigurerAdapter { + + public ClientWebConfig() { + super(); + } + + // API + + @Override + public void addViewControllers(final ViewControllerRegistry registry) { + super.addViewControllers(registry); + + registry.addViewController("/sample.html"); + } + + @Bean + public ViewResolver viewResolver() { + final InternalResourceViewResolver bean = new InternalResourceViewResolver(); + + bean.setViewClass(JstlView.class); + bean.setPrefix("/WEB-INF/view/"); + bean.setSuffix(".jsp"); + + return bean; + } +} \ No newline at end of file diff --git a/spring-beandefinitionstoreexception/src/main/resources/hibernate4Config.xml b/spring-beandefinitionstoreexception/src/main/resources/hibernate4Config.xml deleted file mode 100644 index f35de2a4c5..0000000000 --- a/spring-beandefinitionstoreexception/src/main/resources/hibernate4Config.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - ${hibernate.hbm2ddl.auto} - ${hibernate.dialect} - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-beandefinitionstoreexception/src/main/resources/persistence-mysql.properties b/spring-beandefinitionstoreexception/src/main/resources/persistence-mysql.properties deleted file mode 100644 index a1ff997616..0000000000 --- a/spring-beandefinitionstoreexception/src/main/resources/persistence-mysql.properties +++ /dev/null @@ -1,10 +0,0 @@ -# jdbc.X -jdbc.driverClassName=com.mysql.jdbc.Driver -jdbc.url=jdbc:mysql://localhost:3306/spring_hibernate_dao_01?createDatabaseIfNotExist=true -jdbc.user=tutorialuser -jdbc.pass=tutorialmy5ql - -# hibernate.X -hibernate.dialect=org.hibernate.dialect.MySQL5Dialect -hibernate.show_sql=false -hibernate.hbm2ddl.auto=create-drop diff --git a/spring-beandefinitionstoreexception/src/main/webapp/WEB-INF/web.xml b/spring-beandefinitionstoreexception/src/main/webapp/WEB-INF/web.xml index e0de9aefd4..ba2bb591ed 100644 --- a/spring-beandefinitionstoreexception/src/main/webapp/WEB-INF/web.xml +++ b/spring-beandefinitionstoreexception/src/main/webapp/WEB-INF/web.xml @@ -1,17 +1,42 @@ - - Spring MVC Application - - contextClass - - org.springframework.web.context.support.AnnotationConfigWebApplicationContext - - - - contextConfigLocation - org.baeldung.spring.persistence.config - - - org.springframework.web.context.ContextLoaderListener - + + + Spring MVC Application + + + + contextClass + + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + + contextConfigLocation + org.baeldung.spring.web.config + + + + org.springframework.web.context.ContextLoaderListener + + + + + mvc + org.springframework.web.servlet.DispatcherServlet + 1 + + + mvc + / + + + + index.html + + \ No newline at end of file