小编Md *_*aza的帖子

spring boot:配置Sqlite数据库

我正在尝试使用Sqlite数据库创建一个spring-boot应用程序.

我在pom中添加了sqlite-jdbc和sqlite-dialect依赖项.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>spring-boot-app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.16.1</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.dialect</groupId>
            <artifactId>sqlite-dialect</artifactId>
            <version>0.1.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins> 
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>         
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

和我的apllication.properties文件是:

spring.datasource.url = jdbc:sqlite:test.db
spring.datasource.driver-class-name = org.sqlite.JDBC
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLiteDialect
spring.datasource.username =
spring.datasource.password =

spring.jpa.hibernate.ddl-auto=update
Run Code Online (Sandbox Code Playgroud)

但是我在启动应用程序时遇到异常:

23:42:39.358 [main] INFO  o.a.c.c.StandardService - Stopping service Tomcat
23:42:39.390 [main] WARN  o.s.b.SpringApplication …
Run Code Online (Sandbox Code Playgroud)

java sqlite spring spring-boot

11
推荐指数
1
解决办法
2万
查看次数

WebApplicationContextUtils.getWebApplicationContext(ServletContext) 从 ServletContextListener 返回 NULL

我无法在 ServletContextListener 中获取 WebApplicationContext。我寻找解决方案,但没有一个适合我。如果有人可以提供帮助,我将不胜感激。提前致谢。

以下是代码片段 - 我的 AppConfig 类:

package in.andonsystem.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.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"in.andonsystem"})
public class AppConfig extends WebMvcConfigurerAdapter{

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

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

   @Override
   public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry.addResourceHandler("/static/**").addResourceLocations("/static/");
   }
} …
Run Code Online (Sandbox Code Playgroud)

spring-mvc spring-java-config

6
推荐指数
1
解决办法
7172
查看次数

spring boot oauth2配置:资源服务器保持不受保护

我使用spring boot实现了授权服务器和资源服务器.授权服务器工作正常,我能得到令牌.但我的资源服务器仍然没有受到保护.我的目标是资源服务器只能由具有有效访问令牌的人访问.

我的整个代码是:

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    TokenStore tokenStore;

    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints)
            throws Exception {
        endpoints
            .tokenStore(tokenStore)
            .authenticationManager(authenticationManager);
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients
            .inMemory()
            .withClient("client")
            .scopes("read", "write")
            .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
            .authorizedGrantTypes("password", "refresh_token")
            .secret("secret")
            .accessTokenValiditySeconds(180)
            .refreshTokenValiditySeconds(600);
    }

    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
        super.configure(security); //To change body of generated methods, choose Tools | Templates.
    }

}
Run Code Online (Sandbox Code Playgroud)
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter { …
Run Code Online (Sandbox Code Playgroud)

spring spring-security spring-boot spring-security-oauth2

5
推荐指数
1
解决办法
3258
查看次数

Expo + React Native + 自托管 OTA 不起作用

我正在尝试在我自己的服务器上托管 OTA。我按照您的服务器上的托管更新指南进行操作,但没有成功。

为了更深入地挖掘,我调用了该方法Updates.checkForUpdateAsync()并记录了错误消息。

Error Code: ERR_UPDATES_CHECK
Error Message: Failed to parse manifest data
Run Code Online (Sandbox Code Playgroud)

不过,我检查了清单 URL 并获得了 JSON 响应。

{
  "name": "local-update",
  "slug": "local-update",
  "version": "1.0.13",
  "orientation": "portrait",
  "icon": "./assets/icon.png",
  "splash": {
    "image": "./assets/splash.png",
    "resizeMode": "contain",
    "backgroundColor": "#ffffff",
    "imageUrl": "https://username.github.io/expo-local-update/assets/4dc203c1f48ad8b1e9734613e88be661"
  },
  "updates": {
    "fallbackToCacheTimeout": 0,
    "url": "https://username.github.io/expo-local-update"
  },
  "ios": {
    "supportsTablet": true
  },
  "android": {
    "adaptiveIcon": {
      "foregroundImage": "./assets/adaptive-icon.png",
      "backgroundColor": "#FFFFFF",
      "foregroundImageUrl": "https://username.github.io/expo-local-update/assets/97dae5a0e62ad8551d8a31897b425e63"
    },
    "package": "com.jazasoft.localupdate"
  },
  "web": {
    "favicon": "./assets/favicon.png"
  },
  "sdkVersion": "44.0.0",
  "platforms": [
    "ios", …
Run Code Online (Sandbox Code Playgroud)

android ota react-native expo

5
推荐指数
0
解决办法
710
查看次数

Ratpack Rest API 异常处理程序

我希望在使用ratpack 实现REST API 时使用单个ExceptionHandler 来处理每个异常。此 ExceptionHandler 将处理每个运行时异常并相应地发送 json 响应。

可以在ratpack中实现吗?在 Spring 中,我们使用 @ControllerAdvice 注释来做到这一点。我想使用ratpack 实现类似的行为。

谢谢你的帮助。

java rest spring ratpack

3
推荐指数
1
解决办法
1653
查看次数