iam beginner with spring and want to do so sample project .. i have a database which i want to connect to it .. i used annotaions like AutoWired & service .. But there is problem i can't solve
RegisterationController in Controller Package which have a service i want to call :
@RestController
public class RigesterationController {
@Autowired
private DataManagment dm =new DataManagment() ;
@CrossOrigin(origins = "http://localhost:8060")
@GetMapping("/SignUp/{email}/{UName}/{Pass}/{gender}/{UserType}")
@ResponseBody
public void SignUp(@PathVariable String email , @PathVariable String UName ,
@PathVariable String Pass , @PathVariable char gender , @PathVariable String UserType )
{
boolean valid = dm.Validate(email , Pass ) ; // validate email & Pass
if (valid)
{
if (UserType.equals("s"))
{
StudentAccount studentaccount = new StudentAccount(email , Pass , UName , gender) ;
dm.add(studentaccount) ;
System.out.println("Account Created Successfully" );
}
}
else
{
System.out.println("Invalid Data, Please Try Again" );
}
}
DataManagement Class in first Package :
@Service
public class DataManagment {
@Autowired
private StudentAccountRepository StudentAccount1 ;
public boolean Validate (String email , String Pass )
{
if(!email.contains("@") || email.contains(" ") || (Pass.length()<8) || !email.contains(".com") )
return false;
else
return true;
}
public void add(StudentAccount studentaccount2) {
StudentAccount1.save(studentaccount2) ;
}
StudentAccountRepository in first Package:
package first;
import org.springframework.data.repository.CrudRepository;
public interface StudentAccountRepository extends CrudRepository<StudentAccount,String > {
}
Student Account in first Package .. which refer to the table in database :
package first;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="studentaccount")
public class StudentAccount {
@Id
private String email;
private String password;
private String name ;
private char gender;
public StudentAccount(String email, String password , String name , char gender ) {
super();
this.email = email;
this.password = password;
this.name = name;
this.gender = gender;
}
public StudentAccount() {
super();
this.email = "";
this.password = "";
this.name = "";
this.gender = ' ';
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getGender() {
return gender;
}
public void setGender(char gender) {
this.gender = gender;
}
}
MainController Class
package controller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
public class MainController {
public static void main(String[] args) {
SpringApplication.run(MainController.class, args);
}
}
now i have this Error :
APPLICATION FAILED TO START
Description:
Field dm in controller.RigesterationController required a bean of type 'first.DataManagment' that could not be found.
Action:
Consider defining a bean of type 'first.DataManagment' in your configuration.