This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jeetprksh.h2.boot.entity; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
@Entity | |
public class ApplicationSetting { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jeetprksh.h2.boot.dao; | |
import com.jeetprksh.h2.boot.entity.ApplicationSetting; | |
import org.springframework.data.repository.CrudRepository; | |
public interface AppSettingRepository extends CrudRepository<ApplicationSetting, Integer> { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jeetprksh.h2.boot.app; | |
import com.jeetprksh.h2.boot.dao.AppSettingRepository; | |
import com.jeetprksh.h2.boot.entity.ApplicationSetting; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.boot.autoconfigure.domain.EntityScan; | |
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Datasource | |
spring.datasource.url=jdbc:h2:file:~/embedded-db | |
spring.datasource.username=sa | |
spring.datasource.password= | |
spring.datasource.driver-class-name=org.h2.Driver | |
# JPA | |
spring.jpa.hibernate.ddl-auto=update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn package | |
cd .\target\ | |
java -jar .\h2-springboot-embedded-0.0.1-SNAPSHOT.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<properties> | |
<failOnMissingWebXml>false</failOnMissingWebXml> | |
<spring.version>5.0.0.RELEASE</spring.version> | |
<hibernate.version>5.2.11.Final</hibernate.version> | |
<c3p0.version>0.9.5.2</c3p0.version> | |
<servlets.version>3.1.0</servlets.version> | |
<hsqldb.version>1.8.0.10</hsqldb.version> | |
<jackson.version>2.9.5</jackson.version> | |
<mysql.version>8.0.11</mysql.version> | |
</properties> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppConfig extends AbstractAnnotationConfigDispatcherServletInitializer { | |
@Override | |
protected Class<?>[] getRootConfigClasses() { | |
return new Class[] { HibernateConfig.class }; | |
} | |
@Override | |
protected Class<?>[] getServletConfigClasses() { | |
return new Class[] { WebMvcConfig.class }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableTransactionManagement | |
public class HibernateConfig { | |
@Bean | |
public LocalSessionFactoryBean getSessionFactory() throws PropertyVetoException { | |
LocalSessionFactoryBean bean = new LocalSessionFactoryBean(); | |
Properties hibernateProperties = new Properties(); | |
hibernateProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableWebMvc | |
@ComponentScan("com.spring5.app") | |
public class WebMvcConfig extends WebMvcConfigurationSupport { | |
@Override | |
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | |
converters.add(customJackson2HttpMessageConverter()); | |
super.addDefaultHttpMessageConverters(converters); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController() | |
@RequestMapping("user") | |
public class UserController { | |
@Autowired | |
private UserService service; | |
@RequestMapping(value = "{userId}", method = RequestMethod.GET) | |
public @ResponseBody ServerResponse getUser(@PathVariable("userId") Long userId) { | |
return this.service.getUser(userId); |
OlderNewer