2017-06-06 20 views
0

POST AJAXを実行しますが、エラーが発生しました>プリフライトのレスポンスに無効なHTTPステータスコードがあります403. SpringでPOSTメソッドを作成しました。私はjavascriptに基づいてSAPUI5フロントエンドを使用します)。AJAXエラープリフライトのレスポンスが無効なHTTPステータスコードを持っています

Error and Invalid CORS Request

Headers

ログインしたときに実行春(Mavenプロジェクト):

org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$793b4734] 
> is not eligible for getting processed by all BeanPostProcessors (for 
> example: not eligible for auto-proxying) [INFO] Loaded JDBC driver: 
> com.mysql.jdbc.Driver [INFO] HCANN000001: Hibernate Commons 
> Annotations {4.0.5.Final} [INFO] HHH000412: Hibernate Core 
> {4.3.11.Final} [INFO] HHH000206: hibernate.properties not found [INFO] 
> HHH000021: Bytecode provider name : javassist [INFO] HHH000400: Using 
> dialect: org.hibernate.dialect.MySQLDialect [INFO] HHH000423: 
> Disabling contextual LOB creation as JDBC driver reported JDBC version 
> 2 less than 4 [INFO] HHH000399: Using default transaction strategy 
> (direct JDBC transactions) [INFO] HHH000397: Using 
> ASTQueryTranslatorFactory [INFO] Mapped 
> "{[/tesupdate],methods=[PUT],consumes=[application/json]}" onto public 
> org.springframework.http.ResponseEntity<?> 
> com.project.maven.controller.UserController.update(com.project.maven.entity.KasusEntity) 
> throws java.lang.Exception [INFO] Mapped 
> "{[/tesinsert],methods=[POST],consumes=[application/json]}" onto 
> public org.springframework.http.ResponseEntity<?> 
> com.project.maven.controller.UserController.insert(com.project.maven.entity.KasusEntity) 
> throws java.lang.Exception [INFO] Mapped "{[/**],methods=[OPTIONS]}" 
> onto public void 
> com.project.maven.controller.UserController.corsHeaders(javax.servlet.http.HttpServletResponse) 
> [INFO] Mapped "{[/tesget],methods=[GET]}" onto public java.util.List 
> com.project.maven.controller.UserController.getTes2() throws 
> java.lang.Exception [INFO] Mapped 
> "{[/v2/api-docs],methods=[GET],produces=[application/json || 
> application/hal+json]}" onto public 
> org.springframework.http.ResponseEntity<springfox.documentation.spring.web.json.Json> 
> springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest) 
> [INFO] Mapped "{[/swagger-resources/configuration/security]}" onto 
> org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.SecurityConfiguration> 
> springfox.documentation.swagger.web.ApiResourceController.securityConfiguration() 
> [INFO] Mapped "{[/swagger-resources/configuration/ui]}" onto 
> org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.UiConfiguration> 
> springfox.documentation.swagger.web.ApiResourceController.uiConfiguration() 
> [INFO] Mapped "{[/swagger-resources]}" onto 
> org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> 
> springfox.documentation.swagger.web.ApiResourceController.swaggerResources() 
> [INFO] Mapped URL path [/static/**] onto handler of type [class 
> org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
> [INFO] Mapped URL path [/**/**] onto handler of type [class 
> org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
> [INFO] Looking for @ControllerAdvice: Root WebApplicationContext: 
> startup date [Tue Jun 06 10:22:39 ICT 2017]; root of context hierarchy 
> [INFO] Using DataSource 
> [[email protected]a047] 
> of Hibernate SessionFactory for HibernateTransactionManager [INFO] 
> Starting beans in phase 2147483647 [INFO] Context refreshed [INFO] 
> Found 1 custom documentation plugin(s) [INFO] Scanning for api listing 
> references [INFO] Root WebApplicationContext: initialization completed 
> in 7923 ms Jun 06, 2017 10:22:47 AM 
> org.apache.catalina.core.ApplicationContext log INFO: Initializing 
> Spring FrameworkServlet 'appServlet' [INFO] FrameworkServlet 
> 'appServlet': initialization started [INFO] Refreshing 
> WebApplicationContext for namespace 'appServlet-servlet': startup date 
> [Tue Jun 06 10:22:47 ICT 2017]; parent: Root WebApplicationContext 
> [INFO] Loading XML bean definitions from ServletContext resource 
> [/WEB-INF/config/servlet-context.xml] [INFO] FrameworkServlet 
> 'appServlet': initialization completed in 50 ms Jun 06, 2017 10:22:47 
> AM org.apache.catalina.core.ApplicationContext log INFO: Initializing 
> Spring FrameworkServlet 'dispatcher' [INFO] FrameworkServlet 
> 'dispatcher': initialization started [INFO] Refreshing 
> WebApplicationContext for namespace 'dispatcher-servlet': startup date 
> [Tue Jun 06 10:22:47 ICT 2017]; parent: Root WebApplicationContext 
> [INFO] Registering annotated classes: [class 
> com.project.maven.config.AppConfig] [INFO] JSR-330 
> 'javax.inject.Inject' annotation found and supported for autowiring 
> [INFO] Bean 
> 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' 
> of type [class 
> org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$793b4734] 
> is not eligible for getting processed by all BeanPostProcessors (for 
> example: not eligible for auto-proxying) [INFO] Loaded JDBC driver: 
> com.mysql.jdbc.Driver [INFO] HHH000400: Using dialect: 
> org.hibernate.dialect.MySQLDialect [INFO] HHH000423: Disabling 
> contextual LOB creation as JDBC driver reported JDBC version 2 less 
> than 4 [INFO] HHH000399: Using default transaction strategy (direct 
> JDBC transactions) [INFO] HHH000397: Using ASTQueryTranslatorFactory 
> [INFO] Mapped 
> "{[/tesupdate],methods=[PUT],consumes=[application/json]}" onto public 
> org.springframework.http.ResponseEntity<?> 
> com.project.maven.controller.UserController.update(com.project.maven.entity.KasusEntity) 
> throws java.lang.Exception [INFO] Mapped 
> "{[/tesinsert],methods=[POST],consumes=[application/json]}" onto 
> public org.springframework.http.ResponseEntity<?> 
> com.project.maven.controller.UserController.insert(com.project.maven.entity.KasusEntity) 
> throws java.lang.Exception [INFO] Mapped "{[/**],methods=[OPTIONS]}" 
> onto public void 
> com.project.maven.controller.UserController.corsHeaders(javax.servlet.http.HttpServletResponse) 
> [INFO] Mapped "{[/tesget],methods=[GET]}" onto public java.util.List 
> com.project.maven.controller.UserController.getTes2() throws 
> java.lang.Exception [INFO] Mapped 
> "{[/v2/api-docs],methods=[GET],produces=[application/json || 
> application/hal+json]}" onto public 
> org.springframework.http.ResponseEntity<springfox.documentation.spring.web.json.Json> 
> springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest) 
> [INFO] Mapped "{[/swagger-resources/configuration/security]}" onto 
> org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.SecurityConfiguration> 
> springfox.documentation.swagger.web.ApiResourceController.securityConfiguration() 
> [INFO] Mapped "{[/swagger-resources/configuration/ui]}" onto 
> org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.UiConfiguration> 
> springfox.documentation.swagger.web.ApiResourceController.uiConfiguration() 
> [INFO] Mapped "{[/swagger-resources]}" onto 
> org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> 
> springfox.documentation.swagger.web.ApiResourceController.swaggerResources() 
> [INFO] Using DataSource 
> [[email protected]8a87] 
> of Hibernate SessionFactory for HibernateTransactionManager [INFO] 
> Mapped URL path [/static/**] onto handler of type [class 
> org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
> [INFO] Mapped URL path [/**/**] onto handler of type [class 
> org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
> [INFO] Looking for @ControllerAdvice: WebApplicationContext for 
> namespace 'dispatcher-servlet': startup date [Tue Jun 06 10:22:47 ICT 
> 2017]; parent: Root WebApplicationContext [INFO] Starting beans in 
> phase 2147483647 [INFO] Context refreshed [INFO] Found 1 custom 
> documentation plugin(s) [INFO] Scanning for api listing references 
> [INFO] FrameworkServlet 'dispatcher': initialization completed in 1351 
> ms Jun 06, 2017 10:22:48 AM org.apache.coyote.AbstractProtocol start 
> INFO: Starting ProtocolHandler ["http-bio-8089"] 

コントローラー春:JavaScriptで

@PostMapping(value={"/tesinsert"}, consumes={"application/json"}) 
@ResponseStatus(HttpStatus.CREATED) 
public ResponseEntity<?> insert(@RequestBody KasusEntity user) throws Exception { 
    Map result = new HashMap(); 
    userService.insertTabel(user); 
    return new ResponseEntity<>(result, HttpStatus.CREATED); 
} 

var data = { 
      "kodekasus":5, 
      "nama":"baru", 
      "isdelete":1, 
      "createdby":"hahaa", 
      "createddate":null, 
      "updatedby":"hihii", 
      "updateddate":null 
    }; 

    var url = "http://localhost:8089/SpringNew/tesinsert"; 

    $.ajax({ 
     type: 'POST', 
     url: url, 
     dataType: 'json', 
     data: JSON.stringify(data), 
     success: function(data) { 
      console.log('sukses: '+data); 
     }, 
     error: function(error){ 
      console.log('gagal: '+error); 
      console.log(data); 
     } 
     , 
     headers: { 
      Accept : "application/json", 
      "Content-type": "application/json;charset=UTF-8" 
      } 
    }); 

この問題を解決するにはどうすればよいですか?コードはどこが間違っていますか? javascriptやspringで?私はすでにSwaggerを使ってSpringでinsertメソッドを実行しようとしています。データを挿入できます。私はすでにAJAXを試してみて問題はない。これまではAJAX GETにも問題がありましたが、私はこの問題をajaxの明確な "contentType"で解決しました。しかしAJAX POSTではできません。

ありがとうございました。

ボビー

+0

あなたのajaxコールで.stringify(データ)は必要ありません。data:data、 –

+0

私は既にstringifyを使わずに試してみましたが、同じエラーが表示されます。 – Bobby

+0

エンティティクラス(KasusEntity) –

答えて

0

KasusEntityで、この私のコード:

package com.project.maven.entity; 

import java.io.Serializable; 
import java.util.Date; 

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

@Entity 
@Table(name="KASUS") 
public class KasusEntity implements Serializable { 

    @Id 
    @Column(name="KODE_KASUS") 
    private int kodekasus; 

    @Column(name="NAMA") 
    private String nama; 

    @Column(name="IS_DELETE") 
    private int isdelete; 

    @Column(name="CREATED_BY") 
    private String createdby; 

    @Column(name="CREATED_DATE") 
    private Date createddate;  

    @Column(name="UPDATED_BY") 
    private String updatedby; 

    @Column(name="UPDATED_DATE") 
    private Date updateddate; 

    public int getKodekasus() { 
     return kodekasus; 
    } 

    public void setKodekasus(int kodekasus) { 
     this.kodekasus = kodekasus; 
    } 

    public String getNama() { 
     return nama; 
    } 

    public void setNama(String nama) { 
     this.nama = nama; 
    } 

    public int getIsdelete() { 
     return isdelete; 
    } 

    public void setIsdelete(int isdelete) { 
     this.isdelete = isdelete; 
    } 

    public String getCreatedby() { 
     return createdby; 
    } 

    public void setCreatedby(String createdby) { 
     this.createdby = createdby; 
    } 

    public Date getCreateddate() { 
     return createddate; 
    } 

    public void setCreateddate(Date createddate) { 
     this.createddate = createddate; 
    } 

    public String getUpdatedby() { 
     return updatedby; 
    } 

    public void setUpdatedby(String updatedby) { 
     this.updatedby = updatedby; 
    } 

    public Date getUpdateddate() { 
     return updateddate; 
    } 

    public void setUpdateddate(Date updateddate) { 
     this.updateddate = updateddate; 
    } 

} 

感謝。 Bobby

関連する問題