Tag: spring boot

无法获得spring boot以自动创建数据库模式

当我启动它时,我无法让spring boot自动加载我的数据库模式。 这是我的application.properties: spring.datasource.url=jdbc:mysql://localhost:3306/test spring.datasource.username=test spring.datasource.password= spring.datasource.driverClassName = com.mysql.jdbc.Driver spring.jpa.database = MYSQL spring.jpa.show-sql = true spring.jpa.hibernate.ddl-auto = create spring.jpa.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect spring.jpa.hibernate.naming_strategy = org.hibernate.cfg.ImprovedNamingStrategy 这是我的Application.java: @EnableAutoConfiguration @ComponentScan public class Application { public static void main(final String[] args){ SpringApplication.run(Application.class, args); } } 这是一个示例实体: @Entity @Table(name = “survey”) public class Survey implements Serializable { private Long _id; […]

Spring Boot将HTTP重定向到HTTPS

对于基于Spring Boot的应用程序,我在application.properties上配置了ssl属性,请参阅我的配置: server.port=8443 server.ssl.key-alias=tomcat server.ssl.key-password=123456 server.ssl.key-store=classpath:key.p12 server.ssl.key-store-provider=SunJSSE server.ssl.key-store-type=pkcs12 我在Application.class上添加了连接,就像 @Bean public EmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() { final TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory(); factory.addAdditionalTomcatConnectors(this.createConnection()); return factory; } private Connector createConnection() { final String protocol = “org.apache.coyote.http11.Http11NioProtocol”; final Connector connector = new Connector(protocol); connector.setScheme(“http”); connector.setPort(9090); connector.setRedirectPort(8443); return connector; } 但是,当我尝试以下时 http://127.0.0.1:9090/ 重定向到 https://127.0.0.1:8443/ 没有执行。 谁遇到过类似的问题?

如何与Spring Data REST和JPA保持双向关系?

使用Spring Data REST。 如果您具有oneToMany或ManyToOne关系,则PUT操作在“非拥有”实体上返回200,但实际上不会保留已连接的资源。 示例实体。 @Entity(name = ‘author’) @ToString class AuthorEntity implements Author { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id String fullName @ManyToMany(mappedBy = ‘authors’) Set books } @Entity(name = ‘book’) @EqualsAndHashCode class BookEntity implements Book { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id @Column(nullable = false) String title @Column(nullable = false) String isbn @Column(nullable = […]

Spring Boot,Spring Data JPA,带有多个DataSources

我正在尝试使用Spring Boot和Spring Data JPA将每个@Repositories连接到不同的DataSource。 我使用以下内容http://xantorohara.blogspot.com/2013/11/spring-boot-jdbc-with-multiple.html作为参考。 以下是我试图使用Spring Data JPA实现类似解决方案时使用的代码。 CustomerDbConfig.java (第一个数据源连接) @Configuration @EnableJpaRepositories( entityManagerFactoryRef = “orderEntityManager”, transactionManagerRef = “orderTransactionManager”, basePackages = {“com.mm.repository.customer”}) public class CustomerDbConfig { @Bean(name = “customerEntityManager”) public LocalContainerEntityManagerFactoryBean entityManagerFactory(){ LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource()); em.setPackagesToScan(new String[] {“com.mm.domain.customer”}); JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); em.setJpaVendorAdapter(vendorAdapter); em.setJpaProperties(additionalJpaProperties()); em.setPersistenceUnitName(“customerPersistence”); em.setPackagesToScan(“com.mm.domain.customer”); return em; } Properties additionalJpaProperties(){ Properties […]

Spring-Boot Jersey:允许泽西岛提供静态内容

该应用程序使用JDK 8,Spring Boot和Spring Boot Jersey启动程序,并打包为WAR(尽管它是通过Spring Boot Maven插件在本地运行的)。 我想要做的是将我生成的文档(在构建时)生成为欢迎页面。 我尝试了几种方法: 让Jersey为静态内容提供服务,方法是在application.properties配置正确的init参数,如下所述 引入metadata-complete=false web.xml ,以便将生成的HTML文档列为欢迎文件。 这些都没有成功。 我想避免为了提供静态文件而启用Spring MVC或创建Jersey资源。 任何想法? 这是Jersey配置类(我试图在那里添加ServletProperties.FILTER_STATIC_CONTENT_REGEX失败了): @ApplicationPath(“/”) @ExposedApplication @Component public class ResourceConfiguration extends ResourceConfig { public ResourceConfiguration() { packages(“xxx.api”); packages(“xxx.config”); property(ServerProperties.BV_DISABLE_VALIDATE_ON_EXECUTABLE_OVERRIDE_CHECK, true); property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true); } } 这里是Spring Boot应用程序类(我尝试使用spring.jersey.init.jersey.config.servlet.filter.staticContentRegex=/.*html添加一个application.properties但它没有用,我不确定是什么属性键应该在这里): @SpringBootApplication @ComponentScan @Import(DataConfiguration.class) public class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { […]

注册为Spring bean时,过滤调用两次

我想将@Autowire与Filter一起使用。 所以我在SecurityConfig定义了我的filter,如下所示: @Override protected void configure(HttpSecurity http) throws Exception { http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); http.addFilterBefore(getA(), BasicAuthenticationFilter.class); http.csrf().disable(); } @Bean public A getA(){ return new A(); } 这个filterA扩展了Spring的GenericFilterBean 。 当我调用控制器时,我得到低于输出,这显示filter命中两次。 filter A before filter A before mycontroller invoke filter A after filter A after 我的观察是,这个额外的调用使用Spring容器调用,因为如果filter没有注册为bean,它只会被命中一次。 是什么原因,我该如何解决?

如何为Spring Boot应用程序配置端口

如何配置Spring Boot应用程序侦听的TCP / IP端口,因此它不使用默认端口8080。