如何实现springboot mysql docker windows7?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (142)

代码如下所示:

# DataSource settings: set here your own configurations for the database
# connection. In this example we have "netgloo_blog" as database name and
# "root" as username and password.
spring.datasource.url = jdbc:mysql://mysql-standalone:3306/test
spring.datasource.username = testuser
spring.datasource.password = testuserpass

# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1

# Show or not log for each sql query
spring.jpa.show-sql = true

# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = create

# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager)

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

server.port=8086

Dockerfile如下所示

FROM openjdk:8
ADD target/users-mysql.jar users-mysql.jar
EXPOSE 8086
ENTRYPOINT ["java", "-jar", "users-mysql.jar"]
2018-05-17 20:52:29.921  INFO 1 --- [           main] SpringDataJpaHibernateExampleApplication : Starting SpringDataJpaHibernateExampleApplication v0.0.1-SNAPSHOT o
n b4f3a2acd0a9 with PID 1 (/users-mysql.jar started by root in /)
2018-05-17 20:52:29.937  INFO 1 --- [           main] SpringDataJpaHibernateExampleApplication : No active profile set, falling back to default profiles: default
2018-05-17 20:52:30.124  INFO 1 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConf
igEmbeddedWebApplicationContext@5b37e0d2: startup date [Thu May 17 20:52:30 UTC 2018]; root of context hierarchy
2018-05-17 20:52:34.632  INFO 1 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8086 (http)
2018-05-17 20:52:34.661  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2018-05-17 20:52:34.665  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.14
2018-05-17 20:52:34.873  INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-05-17 20:52:34.873  INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4752 ms
2018-05-17 20:52:35.206  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2018-05-17 20:52:35.220  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-05-17 20:52:35.221  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-05-17 20:52:35.222  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-05-17 20:52:35.222  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-05-17 20:52:36.727  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'd
efault'
2018-05-17 20:52:36.774  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
        name: default
        ...]
2018-05-17 20:52:37.010  INFO 1 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2018-05-17 20:52:37.013  INFO 1 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-05-17 20:52:37.015  INFO 1 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2018-05-17 20:52:37.121  INFO 1 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-05-17 20:52:37.609  INFO 1 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-05-17 20:52:38.541  INFO 1 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
Hibernate: drop table if exists users
Hibernate: create table users (id integer not null, name varchar(255), salary integer, team_name varchar(255), primary key (id))
2018-05-17 20:52:38.712  INFO 1 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2018-05-17 20:52:38.761  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-05-17 20:52:39.881  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.emb
edded.AnnotationConfigEmbeddedWebApplicationContext@5b37e0d2: startup date [Thu May 17 20:52:30 UTC 2018]; root of context hierarchy
2018-05-17 20:52:40.089  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/all/create],methods=[GET]}" onto public java.util.List<c
om.techprimers.jpa.springdatajpahibernateexample.resource.Users> com.techprimers.jpa.springdatajpahibernateexample.resource.Resource.users()
2018-05-17 20:52:40.092  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/all/],methods=[GET]}" onto public java.util.List<com.tec
hprimers.jpa.springdatajpahibernateexample.resource.Users> com.techprimers.jpa.springdatajpahibernateexample.resource.Resource.all()
2018-05-17 20:52:40.103  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springfram
ework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.Ht
tpServletResponse)
2018-05-17 20:52:40.103  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEn
tity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-05-17 20:52:40.180  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.sprin
gframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-17 20:52:40.181  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframewo
rk.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-17 20:52:40.364  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.s
pringframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-17 20:52:41.108  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-05-17 20:52:41.230  INFO 1 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8086 (http)
2018-05-17 20:52:41.252  INFO 1 --- [           main] SpringDataJpaHibernateExampleApplication : Started SpringDataJpaHibernateExampleApplication in 12.225 seconds
(JVM running for 13.208)
提问于
用户回答回答于

虽然所有的事情都发生在windows上,但底层操作系统是linux,所以必须用vm的linux机器的ip地址来替换localhost

扫码关注云+社区

领取腾讯云代金券