Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何使用STS创建一个;弹簧靴&x2B;mysql+;冬眠“;网络服务_Spring_Spring Boot - Fatal编程技术网

Spring 如何使用STS创建一个;弹簧靴&x2B;mysql+;冬眠“;网络服务

Spring 如何使用STS创建一个;弹簧靴&x2B;mysql+;冬眠“;网络服务,spring,spring-boot,Spring,Spring Boot,我是一名android开发者。但是现在,我需要创建一个webservice项目。 我试图通过STS创建一个spring项目。我在网上找到了一些演示代码。但它不起作用。当我运行应用程序时。控制台输出错误日志: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test_spring.customer' doesn't exist at sun.reflect.NativeCon

我是一名android开发者。但是现在,我需要创建一个webservice项目。 我试图通过STS创建一个spring项目。我在网上找到了一些演示代码。但它不起作用。当我运行应用程序时。控制台输出错误日志:

 Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test_spring.customer' doesn't exist
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
        at com.mysql.jdbc.Util.getInstance(Util.java:386)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2825)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2459)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2376)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2360)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:187)
        ... 48 more
  • 错误日志:

     Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test_spring.customer' doesn't exist
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
            at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
            at com.mysql.jdbc.Util.getInstance(Util.java:386)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
            at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
            at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
            at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2825)
            at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156)
            at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2459)
            at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2376)
            at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2360)
            at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:187)
            ... 48 more
    
  • Application.java

    public class Application {
    
        public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(Application.class);
    
        CustomerRepository repository = context.getBean(CustomerRepository.class);
    
        // save a couple of customers
        repository.save(new Customer("Jack", "Bauer"));
        repository.save(new Customer("Chloe", "O'Brian"));
        repository.save(new Customer("Kim", "Bauer"));
        repository.save(new Customer("David", "Palmer"));
        repository.save(new Customer("Michelle", "Dessler"));
    
        // fetch all customers
        Iterable<Customer> customers = repository.findAll();
        System.out.println("Customers found with findAll():");
        System.out.println("-------------------------------");
        for (Customer customer : customers) {
            System.out.println(customer);
        }
        System.out.println();
    
        // fetch an individual customer by ID
        Customer customer = repository.findOne(1L);
        System.out.println("Customer found with findOne(1L):");
        System.out.println("--------------------------------");
        System.out.println(customer);
        System.out.println();
    
        // fetch customers by last name
        List<Customer> bauers = repository.findByLastName("Bauer");
        System.out.println("Customer found with findByLastName('Bauer'):");
        System.out.println("--------------------------------------------");
        for (Customer bauer : bauers) {
            System.out.println(bauer);
        }
    
              context.close();
        }
    }
    
  • CustomerRespository.java

      public interface CustomerRepository extends CrudRepository<Customer, Long> {
    
           List<Customer> findByLastName(String lastName);
      }
    
  • pom.xml

     <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.27</version>
        </dependency>
    </dependencies>
    
    
    org.springframework.boot
    spring引导启动器数据jpa
    org.springframework.boot
    SpringBootStarterWeb
    org.springframework.boot
    弹簧起动试验
    测试
    mysql
    mysql连接器java
    5.1.27
    
=================================

为什么它不自动创建表


请帮助我修复它或告诉我如何创建一个webservice项目,非常感谢。哈哈

我想您可能只需要将以下内容添加到
应用程序。属性

spring.jpa.generate-ddl=true
但是,您还将其配置为使用
sqlserverdialent
。这应该是:

org.hibernate.dialect.MySQL5InnoDBDialect


我认为您可能只需要将以下内容添加到
应用程序.properties

spring.jpa.generate-ddl=true
但是,您还将其配置为使用
sqlserverdialent
。这应该是:

org.hibernate.dialect.MySQL5InnoDBDialect


我建议使用
mysql5innodbdialent
而不是
mysqldialent
。我建议使用
mysql5innodbdialent
而不是
mysqldialent