0

I got this error.Some solutions said add javax.transaction to pom.xml.I did but not working.And some solutions said javaee.jar and javax.persistence.jar to my classpath.But not working.So how to i fix it?

User model

    @Entity
@Table(name="users")
public class Users implements Serializable {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id")
    private Integer id;

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

    @Column(name="surname")
    private String surname;

    @Column(name="username")
    private String username;

    @Column(name="password")
    private String password;

    @Column(name="is_super_user")
    private Boolean isSuperUser;

    @Column(name="email")
    private String email;


    @Column(name="created_at")
    private Date created_at;

    @Column(name="updated_at")
    private Date updated_at;


    @PrePersist
    protected void onCreate() {
        created_at = new Date();
    }

    @PreUpdate
    protected void onUpdate() {
        updated_at = new Date();
    }//and getter&setter

UserDao

@Repository
public class UsersDao {

    @PersistenceContext
    private EntityManager entityManager;

    public void save(Users users){
        entityManager.persist(users);
    }
}

UserDto like model without this constructor

public UsersDto(){

}

public UsersDto(Users users){
    this.id = users.getId();
    this.name = users.getName();
    this.surname = users.getSurname();
    this.email = users.getEmail();
    this.isSuperUser = users.getSuperUser();
    this.username = users.getUsername();
    this.password = users.getPassword();
}

UserResources

    @Component
@Path("/users")
public class UsersResources {
    @Autowired
    UsersService usersService;

    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response saveCity(UsersDto usersDto){
        Users users;

        try{
            users = usersService.saveUsers(usersDto);

        }catch (Exception e){
            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
        }
        return Response.ok(users).build();
    }
}

UserServices

    @Service
public class UsersService {

    @Autowired
    private UsersDao usersDao;

    @Transactional
    public Users saveUsers(UsersDto usersDto){

        Users users = new Users();
        users.setName(usersDto.getName());
        users.setEmail(usersDto.getEmail());
        users.setSuperUser(usersDto.getSuperUser());
        users.setSurname(usersDto.getSurname());
        users.setPassword(usersDto.getPassword());
        usersDao.save(users);

        return users;
    }

}

Error:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/SystemException
    at 
    ... 27 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/transaction/SystemException
    at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
    at java.base/java.lang.Class.forName(Class.java:375) ~[na:na]
    at org.jboss.logging.Logger$1.run(Logger.java:2554) ~[jboss-logging-3.3.2.Final.jar:3.3.2.Final]

My pom.xml has spring boot starter (web security jersey jpa mysql) and javax.transaction

So how to i fix?

more
  • 183
  • 1
  • 7
  • 18
  • Try to understand where the class is supposed to be coming from. If you want to know for sure if a `.class` existing in a `.jar` file then you can unzip the `.jar` and make sure it's actually there. `unzip some-lib.jar`. Once you find what `.jar` the `.class` is in then you need to make sure it's included in the classpath. ie the argument to `java -cp ...` – flakes Mar 07 '18 at 09:35
  • 1
    Maybe this help: [hibernate-java-9-and-systemexception](https://stackoverflow.com/questions/46515230/hibernate-java-9-and-systemexception) They also wrote something about `Caused by: java.lang.NoClassDefFoundError: javax/transaction/SystemException` in a Spring Boot environment. – Andre Albert Mar 07 '18 at 10:19
  • Unfortunately I tried all solutions but did not working.If you want to try https://github.com/SmartAdvertisement/WebApi .I think maybe because of dependency failure – more Mar 07 '18 at 11:34

1 Answers1

0

You made javax:javaee-web-api:6.0 be a provided-scope dependency in your pom.xml file. This is stating that you expect it to be provided by your container at runtime. The NoClassDefFoundException would seem to indicate it is not being provided at runtime (maybe you're using Tomcat instead of TomEE?).

Try removing the <scope> element from the javaee-web-api dependency in pom.xml - you may well just get different errors at runtime (if you don't have an implementation available, for example), but this will get you past this specific error.

David Conneely
  • 896
  • 6
  • 9
  • I got this error when `mvn install` .I have not use TomEE yet.I created project by spring initlzr.This mean I do not think there is any dependency dispute.So i removed `` element from the `javaee-web-api` . Unfortunately the error has not changed. – more Mar 08 '18 at 06:44