Skip to content

Commit

Permalink
during change to spring mvc framework - first backup
Browse files Browse the repository at this point in the history
  • Loading branch information
ntut-ben committed Nov 2, 2019
1 parent db0eef8 commit f431a1f
Show file tree
Hide file tree
Showing 2,106 changed files with 2,807 additions and 1,643 deletions.
6 changes: 3 additions & 3 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
Expand Down
9 changes: 9 additions & 0 deletions .settings/org.eclipse.wst.common.component
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">

<wb-module deploy-name="ezfit-0.0.1-SNAPSHOT">

<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>

<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>

<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>

<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>

<property name="context-root" value="ezfit"/>

<property name="java-output-path" value="/ezfit/target/classes"/>

</wb-module>

</project-modules>
2 changes: 1 addition & 1 deletion .settings/org.eclipse.wst.common.project.facet.core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<fixed facet="wst.jsdt.web"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.1"/>
<installed facet="jst.web" version="4.0"/>
</faceted-project>
2 changes: 1 addition & 1 deletion .springBeans
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/main/webapp/WEB-INF/applicationContext.xml</config>
<config>src/main/resources/beans.xml</config>
</configs>
<autoconfigs>
</autoconfigs>
Expand Down
119 changes: 32 additions & 87 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,137 +6,82 @@
<artifactId>ezfit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<failOnMissingWebXml>fasle</failOnMissingWebXml>
<spring.version>5.2.0.RELEASE</spring.version>
<hibernate.version>5.4.6.Final</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<!-- 動態網頁 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2.1-b04</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
</dependency>

<!-- Hibernate framework -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.0.Final</version>
</dependency>

<!-- Spring FrameWork -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.0.RELEASE</version>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
<!-- Spring Framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.2.0.RELEASE</version>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.2.0.RELEASE</version>
<version>${spring.version}</version>
</dependency>
<!-- JDK 9 之後要加入下列四個<dependency> -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Hibernate Framewrok -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.9.3</version>
</dependency>

<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

</project>
4 changes: 2 additions & 2 deletions src/main/java/_00/filter/ServiceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
/**
* Servlet Filter implementation class ServiceController
*/
@WebFilter({ "/ListIngredient.do", "/MemberLogin.do", "/ShopCart.do", "/CheckShopCart.do", "/login/loginServlet.do",
"/OrderProcess.do", "/MealBox.do", "/PlaneProductRetrieve.do", "/GroupBuy.do" })
//@WebFilter({ "/ListIngredient.do", "/MemberLogin.do", "/ShopCart.do", "/CheckShopCart.do", "/login/loginServlet.do",
// "/OrderProcess.do", "/MealBox.do", "/PlaneProductRetrieve.do", "/GroupBuy.do" })
public class ServiceController implements Filter {

SessionFactory factory;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/_99/TestJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import _00.utils.HibernateUtils;
import _00.utils.ToJson;
import createAccount.model.MemberBean;
import login.service.LoginService;
import login.service.LoginServiceImpl;
import shopping.model.CartItem;
import shopping.service.impl.CartItemServiceImpl;
Expand All @@ -18,7 +19,7 @@ public static void main(String args[]) {

SessionFactory factory = HibernateUtils.getSessionFactory();
Session session = factory.getCurrentSession();
LoginServiceImpl loginServiceImpl = new LoginServiceImpl();
LoginService loginServiceImpl = new LoginServiceImpl();
CartItemServiceImpl cartItemServiceImpl = new CartItemServiceImpl();
ToJson<CartItem> toJson = new ToJson<CartItem>();
Transaction tx = null;
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/config/RootAppConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package config;

import java.beans.PropertyVetoException;
import java.util.Properties;

import javax.sql.DataSource;

import org.hibernate.SessionFactory;
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.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.mchange.v2.c3p0.ComboPooledDataSource;

@Configuration
@EnableTransactionManagement
@ComponentScan({ "shopping.repository", "shopping.service", "createAccount.repository", "createAccount.service",
"login.service" })
public class RootAppConfig {

@Bean
public DataSource dataSource() {
ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setUser("root");
ds.setPassword("1qaz@WSX");
try {
ds.setDriverClass("com.mysql.cj.jdbc.Driver");
} catch (PropertyVetoException e) {
e.printStackTrace();
}
ds.setJdbcUrl(
"jdbc:mysql://localhost:3306/ezfit?useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Taipei");
ds.setInitialPoolSize(4);
ds.setMaxPoolSize(8);
return ds;
}

@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean factory = new LocalSessionFactoryBean();
factory.setDataSource(dataSource());
factory.setPackagesToScan(new String[] { "createAccount.model", "shopping.model", "login.model" });
factory.setHibernateProperties(additionalProperties());
return factory;
}

@Bean(name = "transactionManager")
@Autowired
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {

HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactory);
return txManager;
}

private Properties additionalProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", org.hibernate.dialect.MySQL8Dialect.class);
properties.put("hibernate.show_sql", Boolean.FALSE);
properties.put("hibernate.format_sql", Boolean.TRUE);
properties.put("default_batch_fetch_size", 10);
properties.put("hibernate.hbm2ddl.auto", "update");
return properties;
}
}
50 changes: 50 additions & 0 deletions src/main/java/config/WebAppConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package config;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan({ "shopping.controller", "home.controller", "createAccount.controller", "login.controller" })
public class WebAppConfig implements WebMvcConfigurer {

@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
internalResourceViewResolver.setPrefix("/WEB-INF/views/");
internalResourceViewResolver.setSuffix(".jsp");
return internalResourceViewResolver;
}

@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
resourceBundleMessageSource.setBasename("messages");
return resourceBundleMessageSource;
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("createAccount/pic/**").addResourceLocations("/WEB-INF/views/createAccount/pic/");
registry.addResourceHandler("createAccount/js/**").addResourceLocations("/WEB-INF/views/createAccount/js/");
registry.addResourceHandler("createAccount/css/**").addResourceLocations("/WEB-INF/views/createAccount/css/");
registry.addResourceHandler("login/**").addResourceLocations("/WEB-INF/views/login/");
registry.addResourceHandler("index/img/**").addResourceLocations("/WEB-INF/views/index/img/");
registry.addResourceHandler("index/js/**").addResourceLocations("/WEB-INF/views/index/js/");
registry.addResourceHandler("index/css/**").addResourceLocations("/WEB-INF/views/index/css/");
registry.addResourceHandler("/productImage/**").addResourceLocations("/WEB-INF/views/productImage/");
registry.addResourceHandler("/css/**").addResourceLocations("/WEB-INF/views/css/");
registry.addResourceHandler("/js/**").addResourceLocations("/WEB-INF/views/js/");
registry.addResourceHandler("/images/**").addResourceLocations("/WEB-INF/views/images/");
registry.addResourceHandler("/img/**").addResourceLocations("/WEB-INF/views/img/");
}

}
Loading

0 comments on commit f431a1f

Please sign in to comment.