当前位置: 首页 > 知识库问答 >
问题:

使用SPRING引导(SOAP服务)连接Oracle数据库时出现问题

司空修贤
2023-03-14

早上好,我是spring boot的新手,我正在构建一个SOAP服务,该服务允许查询ORACLE数据库(该数据库位于容器中),但我面临以下无法解决的错误:

应用程序启动失败

描述:

SpringBootSoapApp.java

package com.example.conexion.soap_service_example;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class SpringBootSoapApp {

    public static void main(String[] args) {
        SpringApplication.run(SpringBootSoapApp.class, args);
    }
}

client.java

package com.example.conexion.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Cliente {

    @Id
    @Column(name="CEDULA")
    private int cedula;
    @Column(name="NOMBRE")
    private String nombre;
    @Column(name="APELLIDO")
    private String apellido;
    @Column(name="TIPO_CLIENTE")
    private String tipo_cliente;

    // Getter y Setters
    public int getCedula() {
        return cedula;
    }
    public void setCedula(int cedula) {
        this.cedula = cedula;
    }
    public String getNombre() {
        return nombre;
    }
    public void setNombre(String nombre) {
        this.nombre = nombre;
    }
    public String getApellido() {
        return apellido;
    }
    public void setApellido(String apellido) {
        this.apellido = apellido;
    }
    public String getTipo_cliente() {
        return tipo_cliente;
    }
    public void setTipo_cliente(String tipo_cliente) {
        this.tipo_cliente = tipo_cliente;
    }


}

ClienteService.java

package com.example.conexion.service;
import com.example.conexion.entity.Cliente;
import java.util.List;


public interface ClienteService {

    public Cliente getClienteById(long id);
    public List<Cliente> getAllClientes();
}
package com.example.conexion.repository;
import org.springframework.data.repository.CrudRepository;

import com.example.conexion.entity.Cliente;

public interface ClienteRepository extends CrudRepository <Cliente,Integer> {

    public Cliente findById(int cedula);

}
package com.example.conexion.endpoint;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import com.example.conexion.entity.Cliente;
import com.example.conexion.service.ClienteService;

import com.example.conexion.ws.ClienteType;
import com.example.conexion.ws.GetAllClientesRequest;
import com.example.conexion.ws.GetAllClientesResponse;
import com.example.conexion.ws.GetClienteByIdRequest;
import com.example.conexion.ws.GetClienteByIdResponse;

@Endpoint
public class ClienteEndpoint {

    public static final String NAMESPACE_URI = "http://www.javaspringclub.com/movies-ws";

    private ClienteService service;

    public ClienteEndpoint() {

    }

    @Autowired
    public ClienteEndpoint(ClienteService service) {
        this.service = service;
    }

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getClienteByIdRequest")
    @ResponsePayload
    public GetClienteByIdResponse getMovieById(@RequestPayload GetClienteByIdRequest request) {
        GetClienteByIdResponse response = new GetClienteByIdResponse();
        Cliente clienteEntity = service.getClienteById(request.getClienteCedula());
        ClienteType clienteType = new ClienteType();
        BeanUtils.copyProperties(clienteEntity, clienteType);
        response.setClienteType(clienteType);
        return response;

    }

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getAllMoviesRequest")
    @ResponsePayload
    public GetAllClientesResponse getAllMovies(@RequestPayload GetAllClientesRequest request) {
        GetAllClientesResponse response = new GetAllClientesResponse();
        List<ClienteType> clienteTypeList = new ArrayList<ClienteType>();
        List<Cliente> clienteEntityList = service.getAllClientes();
        for (Cliente cliente : clienteEntityList) {
            ClienteType clienteType = new ClienteType();
            BeanUtils.copyProperties(cliente, clienteType);
            clienteTypeList.add(clienteType);
        }
        response.getClienteType().addAll(clienteTypeList);

        return response;

    }
package com.example.conexion.config;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;
import com.example.conexion.endpoint.ClienteEndpoint;

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {

     @SuppressWarnings({ "rawtypes", "unchecked" })
        @Bean
        public ServletRegistrationBean messageDispatcherServlet(ApplicationContext appContext){
            MessageDispatcherServlet servlet = new MessageDispatcherServlet();
            servlet.setApplicationContext(appContext);
            servlet.setTransformWsdlLocations(true);
            return new ServletRegistrationBean(servlet, "/ws/*");
        }

        // localhost:8080/ws/movies.wsdl
        @Bean(name = "clientes")
        public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema schema){
            DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
            wsdl11Definition.setPortTypeName("ClientesPort");
            wsdl11Definition.setLocationUri("/ws");
            wsdl11Definition.setTargetNamespace(ClienteEndpoint.NAMESPACE_URI);
            wsdl11Definition.setSchema(schema);
            return wsdl11Definition;
        }

        @Bean
        public XsdSchema moviesSchema(){
            return new SimpleXsdSchema(new ClassPathResource("cliente.xsd"));
        }
}
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="http://www.javaspringclub.com/movies-ws"
    targetNamespace="http://www.javaspringclub.com/movies-ws"
    elementFormDefault="qualified">

    <xs:element name="getClienteByIdRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="clienteCedula" type="xs:long" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="getClienteByIdResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="clienteType" type="tns:clienteType" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="clienteType">
        <xs:sequence>
            <xs:element name="cedula" type="xs:int" />
            <xs:element name="name" type="xs:string" />
            <xs:element name="apellido" type="xs:string" />
            <xs:element name="tipo_cliente" type="xs:string" />
        </xs:sequence>
    </xs:complexType>

 <xs:element name="getAllClientesRequest">
        <xs:complexType/>
    </xs:element>    
    <xs:element name="getAllClientesResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="clienteType" type="tns:clienteType" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>    
# Oracle settings

spring.datasource.url=jdbc:oracle:thin:@//10.164.7.203:1521/ORCLPDB1.localdomain
spring.datasource.username=cesar
spring.datasource.password=xxxxx123
spring.datasource.driver-class-oracle.jdbc.driver.OracleDriver

spring.main.banner-mode=off

spring.jpa.hibernate.ddl-auto=update
<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.conexion</groupId>
  <artifactId>soap-service-example</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>soap-service-example</name>
  <url>http://maven.apache.org</url>

  <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
  </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.M4</version>
        <relativePath /> <!-- lookup parent from repository -->
      </parent> 

      <dependencies>
            <dependency>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.0-api</artifactId>
                <version>1.0.1.Final</version>
            </dependency>
            <dependency>
                <groupId>javax.persistence</groupId>
                 <artifactId>persistence-api</artifactId>
                 <version>1.0.2</version>
             </dependency>  
             <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web-services</artifactId>
                </dependency>
            <dependency>
                <groupId>com.oracle.jdbc</groupId>
                <artifactId>ojdbc8</artifactId>
                <version>12.2.0.1</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jdbc</artifactId>
                <version>2.2.4.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>   
            <dependency>
                <groupId>wsdl4j</groupId>
                <artifactId>wsdl4j</artifactId>
                </dependency>

      </dependencies>

      <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>jaxb2-maven-plugin</artifactId>
                    <version>2.5.0</version>
                    <executions>
                        <execution>
                            <id>xjc-schema</id>
                            <goals>
                                <goal>xjc</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <sources>
                            <source>src/resources/cliente.xsd</source>
                        </sources>
                        <packageName>com.example.conexion.ws</packageName>
                        <schemaDirectory>${project.basedir}/src/main/resources/</schemaDirectory>
                        <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
                        <clearOutputDir>false</clearOutputDir>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                      <source>1.8</source>
                      <target>1.8</target>
                    </configuration>
                  </plugin>
            </plugins>
        </build>
        <repositories>
            <!-- Repository for ORACLE JDBC Driver -->
            <repository>
                <id>codelds</id>
                <url>https://code.lds.org/nexus/content/groups/main-repo</url>
            </repository>
                <repository>
                <id>spring-snapshots</id>
                <name>Spring Snapshots</name>
                <url>https://repo.spring.io/snapshot</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>spring-milestones</id>
                <name>Spring Milestones</name>
                <url>https://repo.spring.io/milestone</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>spring-snapshots</id>
                <name>Spring Snapshots</name>
                <url>https://repo.spring.io/snapshot</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <id>spring-milestones</id>
                <name>Spring Milestones</name>
                <url>https://repo.spring.io/milestone</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
</project>

从@enableAutoConfiguration(exclude={datasourceAutoConfiguration.class})中删除该行,这将禁用数据源的自动配置,但会引发另一个错误:

应用程序启动失败

描述:

共有1个答案

谢典
2023-03-14

我在您的配置中发现了一个错误,行->spring.datasource.driver-class-oracle.jdbc.driver.oracledriver应该是->spring.datasource.driver-class-name=oracle.jdbc.driver.oracledriver

 类似资料:
  • 我只是克隆了一台托管Oracle的服务器,以便制作一台linux测试机。但是sqlplus用户/password@alias克隆服务器上的连接不工作。我找不到要改变的东西。提前谢谢你 以下是源服务器的配置文件: 主机名: [root@server1]#cat/etc/主机 192.168.0.11server1.domain.com服务器1 全球名称: 从global\u name中选择*; my

  • 我有一个IP地址每次我收到连接失败的消息时,我都尝试了很多连接到该服务器的方法。出于安全原因,我隐藏了用户名和密码。 代码: 我有例外 组织。postgresql。util。PSQLException:连接尝试失败。在org。postgresql。果心v3。连接工厂impl。org上的openConnectionImpl(ConnectionFactoryImpl.java:292)。postgr

  • 我收到一个错误: 编辑:链接到堆栈跟踪 下面是错误的最后一个“部分”,表示这是一个: ' 我的URL字符串:“jdbc:mysql://127.0.0.1:3306/schemaname?useUnicode=true 我的连接代码片段: 我已经使用了正确的模式/库名、用户名、密码和所有其他所需的“需求”。我还设置了绑定地址为,端口为。数据库是在线的,我已经确保服务正在运行。

  • 我正在构建一个Django应用程序,它有几个应用程序。使用SQLite数据库作为后端运行良好。当我试图使用“manage.py migrate”将后端迁移到Oracle时,我发现了以下错误 django.db.utils.DatabaseError:ORA-01950:对表空间“XXXXXX”没有权限 当我在数据库中检查我的用户权限时,它有创建表、视图等的权限。我尝试执行“manage.py sq

  • 我正在使用sqldeveloper查询数据库并将结果导出到csv文件。我每天都需要这个文件,所以考虑创建可以在windows任务调度器上调度的bat文件。我在研究它,发现我可以使用SQLcl运行脚本来导出查询数据。但不知何故,我无法连接它,它给了我一个错误“ORA-01017:无效的用户名/密码;登录被拒绝。以下是我的sql developer连接属性 这是我的命令行: 我安装了java开发工具包

  • 我使用spring boot data redis连接到redis群集,使用版本2.1.3,配置如下: 但是,在操作过程中,始终会收到警告异常消息,如下所示: 这似乎是莴苣的问题,如何映射远程主机