2016-07-29 125 views
1

我有一個稱爲「階段」的配置文件,我試圖實現一個web服務,但每當我提出請求時,我得到一些錯誤,每當我刪除配置文件註釋它通常工作,我真的不知道爲什麼不與輪廓在這裏工作有一些類:春天配置文件配置

@SpringBootApplication 
public class MyApp{ 

    public static void main(String[] args) { 
     AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); 
      context.getEnvironment().setActiveProfiles("stage"); 
      context.register(MyApp.class);  
      SpringApplication.run(MyApp.class, args); 

    } 

} 
@Profile("stage") 
@Configuration 
@PropertySource(value = { "classpath:jdbc.properties" }) 
public class StageDSConfig { 

    @Value("${jdbc.driverClassName}") 
    private String driverClassName; 
    @Value("${jdbc.url}") 
    private String jdbcURL; 
    @Value("${jdbc.username}") 
    private String username; 
    @Value("${jdbc.password}") 
    private String password; 

    @Bean 
    public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() { 
     return new PropertySourcesPlaceholderConfigurer(); 
    } 

    @Bean 
    public DataSource dataSource() { 

     BasicDataSource dataSource = new BasicDataSource(); 
     dataSource.setDriverClassName(driverClassName); 
     dataSource.setUrl(jdbcURL); 
     dataSource.setUsername(username); 
     dataSource.setPassword(password); 
     DatabasePopulatorUtils.execute(createDatabasePopulator(), dataSource); 
     return dataSource; 
    } 

    private DatabasePopulator createDatabasePopulator() { 
     ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); 
     databasePopulator.setContinueOnError(true); 
     databasePopulator.addScript(new ClassPathResource("schema-mysql.sql")); 
     databasePopulator.addScript(new ClassPathResource("data-mysql.sql")); 
     return databasePopulator; 
    } 
} 
@EnableWs 
@Configuration 
public class WebServiceConfig extends WsConfigurerAdapter { 

    @Bean 
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { 
     MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 
     servlet.setApplicationContext(applicationContext); 

     servlet.setTransformWsdlLocations(true); 
     return new ServletRegistrationBean(servlet, "/ws/*"); 
    } 

    @Bean(name = "ws") 
    public DefaultWsdl11Definition defaultActionWsdl11Definition(XsdSchema actionSchema) { 
     DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); 
     wsdl11Definition.setPortTypeName("ActionPort"); 
     wsdl11Definition.setLocationUri("/ws"); 
     wsdl11Definition.setTargetNamespace("http://www.example.com/ws"); 
     wsdl11Definition.setSchema(actionSchema); 
     return wsdl11Definition; 
    } 

    @Bean 
    public XsdSchema wsSchema() { 
     return new SimpleXsdSchema(new ClassPathResource("ws.xsd")); 
    } 

} 

,這是錯誤日誌:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP-ENV:Header/> 
    <SOAP-ENV:Body> 
     <SOAP-ENV:Fault> 
     <faultcode>SOAP-ENV:Server</faultcode> 
     <faultstring xml:lang="en">PreparedStatementCallback; bad SQL grammar [INSERT INTO logs(ipAddress,actionn,requestBody) values(?,?,?)]; nested exception is java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: LOGS</faultstring> 
     </SOAP-ENV:Fault> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

回答

2

我相信你沒有正確激活的配置文件。隨着springBoot,你可以這樣設置配置文件:

new SpringApplicationBuilder(MyApp.class).profiles("stage").run(args); 

或者,通過一個環境變量:

System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "stage"); 
SpringApplication.run(MyApp.class, args); 
+0

是的謝謝你是這個問題,我沒有正確激活配置文件 – imoteb

1

我認爲問題是,你實際上並沒有激活「舞臺」的個人資料,所以上下文缺少StageDSConfig類中的所有bean,因此沒有創建模式